#!/bin/bash
# ============================================
# 备份系统验证脚本 (Backup System Verification Script)
# ============================================
# 脚本用途 (Script Purpose):
#   全面验证备份系统的配置、权限、脚本和功能，确保备份系统能够正常运行
#   Comprehensively verify backup system configuration, permissions, scripts and functionality to ensure backup system runs normally
# 作者信息 (Author Information):
#   Ansible自动化部署系统 (Ansible Automated Deployment System)
# 版本信息 (Version Information):
#   版本 1.0 - 初始版本，包含核心验证功能
#   Version 1.0 - Initial version with core verification functionality
# 使用方法 (Usage):
#   ./scripts/verify-backup.sh
#   执行前请确保具有适当的系统权限
#   Please ensure appropriate system permissions before execution
# 
# 脚本详细功能说明 (Detailed Script Functionality):
#   1. 目录结构验证 (Directory Structure Verification):
#      - 验证备份目录结构和权限配置的完整性 (Verify backup directory structure and permission configuration integrity)
#      - 检查主备份目录、子目录、日志目录的存在性 (Check existence of main backup directory, subdirectories, log directories)
#      - 验证目录权限和所有权设置的安全性 (Verify security of directory permissions and ownership settings)
#   2. 脚本文件验证 (Script File Verification):
#      - 检查备份脚本的存在性、可执行性和语法正确性 (Check backup script existence, executability and syntax correctness)
#      - 验证核心备份脚本：backup.sh, restore.sh, verify.sh等 (Verify core backup scripts: backup.sh, restore.sh, verify.sh, etc.)
#      - 检查脚本权限和语法完整性 (Check script permissions and syntax integrity)
#   3. 配置文件验证 (Configuration File Verification):
#      - 验证备份配置文件和关键参数设置 (Verify backup configuration files and key parameter settings)
#      - 检查备份策略、压缩、加密等配置项 (Check backup strategy, compression, encryption and other configuration items)
#      - 验证保留策略和清理规则配置 (Verify retention policy and cleanup rule configuration)
#   4. 用户权限验证 (User Permission Verification):
#      - 检查备份用户账户、权限和sudo配置 (Check backup user accounts, permissions and sudo configuration)
#      - 验证备份用户的系统权限和访问控制 (Verify backup user system permissions and access control)
#      - 检查用户主目录和shell环境配置 (Check user home directory and shell environment configuration)
#   5. 定时任务验证 (Scheduled Task Verification):
#      - 验证定时任务（cron/systemd）的配置状态 (Verify scheduled task (cron/systemd) configuration status)
#      - 检查备份作业的调度配置和执行频率 (Check backup job scheduling configuration and execution frequency)
#      - 验证定时任务的权限和环境设置 (Verify scheduled task permissions and environment settings)
#   6. 系统资源验证 (System Resource Verification):
#      - 检查日志轮转配置和磁盘空间使用情况 (Check log rotation configuration and disk space usage)
#      - 验证备份存储空间的可用性和容量 (Verify backup storage space availability and capacity)
#      - 监控系统资源使用状况和性能指标 (Monitor system resource usage and performance metrics)
#   7. 功能测试验证 (Functionality Test Verification):
#      - 测试备份功能的实际可用性和性能 (Test actual availability and performance of backup functionality)
#      - 验证备份和恢复流程的完整性 (Verify integrity of backup and restore processes)
#      - 检查备份文件的完整性和可恢复性 (Check integrity and recoverability of backup files)
#   8. 报告生成功能 (Report Generation Functionality):
#      - 生成详细的验证报告和改进建议 (Generate detailed verification reports and improvement recommendations)
#      - 提供系统状态总结和问题诊断信息 (Provide system status summary and problem diagnosis information)
#      - 输出优化建议和最佳实践指导 (Output optimization recommendations and best practice guidance)
# ============================================

# ============================================
# 输出颜色配置 (Output Color Configuration)
# ============================================
# 功能说明 (Function Description):
#   定义脚本输出的颜色代码，用于增强可读性和状态区分
#   Define color codes for script output to enhance readability and status differentiation
# 颜色用途 (Color Usage):
#   - RED: 错误信息和失败状态 (Error messages and failure status)
#   - GREEN: 成功信息和通过状态 (Success messages and pass status)
#   - YELLOW: 警告信息和注意事项 (Warning messages and notices)
#   - BLUE: 信息提示和标题显示 (Information prompts and title display)
#   - NC: 重置颜色，恢复默认终端颜色 (Reset color, restore default terminal color)
# ============================================
RED='\033[0;31m'     # 红色 - 用于错误和失败状态 (Red - for errors and failure status)
GREEN='\033[0;32m'   # 绿色 - 用于成功和通过状态 (Green - for success and pass status)
YELLOW='\033[1;33m'  # 黄色 - 用于警告和注意事项 (Yellow - for warnings and notices)
BLUE='\033[0;34m'    # 蓝色 - 用于信息和标题显示 (Blue - for information and title display)
NC='\033[0m'         # 无颜色 - 重置为默认颜色 (No Color - reset to default color)

# ============================================
# 备份系统路径配置 (Backup System Path Configuration)
# ============================================
# 功能说明 (Function Description):
#   定义备份系统的核心路径和配置文件位置
#   Define core paths and configuration file locations for the backup system
# 路径说明 (Path Description):
#   - BACKUP_BASE_DIR: 备份数据存储根目录 (Backup data storage root directory)
#   - BACKUP_SCRIPTS_DIR: 备份脚本存储目录 (Backup script storage directory)
#   - BACKUP_CONFIG_FILE: 主配置文件路径 (Main configuration file path)
#   - BACKUP_LOG_DIR: 备份日志存储目录 (Backup log storage directory)
#   - BACKUP_USER: 备份系统运行用户 (Backup system runtime user)
# 安全考虑 (Security Considerations):
#   - 确保路径权限设置正确，防止未授权访问 (Ensure correct path permissions to prevent unauthorized access)
#   - 备份目录应具有适当的所有权和访问控制 (Backup directories should have appropriate ownership and access control)
# ============================================
BACKUP_BASE_DIR="/backup"                    # 备份数据存储根目录 - 所有备份文件的主存储位置
BACKUP_SCRIPTS_DIR="/opt/backup"             # 备份脚本存储目录 - 存放所有备份相关脚本
BACKUP_CONFIG_FILE="/etc/backup/backup.conf" # 备份配置文件路径 - 主配置文件位置
BACKUP_LOG_DIR="/var/log/backup"             # 备份日志存储目录 - 备份操作日志文件位置
BACKUP_USER="backup"                         # 备份系统专用用户 - 执行备份操作的系统用户

# ============================================
# 验证结果计数器 (Verification Result Counters)
# ============================================
# 功能说明 (Function Description):
#   定义用于统计验证结果的全局计数器变量
#   Define global counter variables for tracking verification results
# 计数器说明 (Counter Description):
#   - TOTAL_CHECKS: 总检查项目数量，记录所有执行的验证项目 (Total number of check items, records all executed verification items)
#   - PASSED_CHECKS: 通过检查数量，记录验证成功的项目 (Number of passed checks, records successfully verified items)
#   - FAILED_CHECKS: 失败检查数量，记录验证失败的项目 (Number of failed checks, records failed verification items)
#   - WARNING_CHECKS: 警告检查数量，记录需要注意但不影响基本功能的项目 (Number of warning checks, records items that need attention but don't affect basic functionality)
# 使用方式 (Usage):
#   这些计数器在print_result函数中自动更新，用于生成最终的统计报告
#   These counters are automatically updated in the print_result function for generating final statistical reports
# 统计意义 (Statistical Significance):
#   - 成功率 = PASSED_CHECKS / TOTAL_CHECKS * 100% (Success rate = PASSED_CHECKS / TOTAL_CHECKS * 100%)
#   - 失败率 = FAILED_CHECKS / TOTAL_CHECKS * 100% (Failure rate = FAILED_CHECKS / TOTAL_CHECKS * 100%)
#   - 警告率 = WARNING_CHECKS / TOTAL_CHECKS * 100% (Warning rate = WARNING_CHECKS / TOTAL_CHECKS * 100%)
# ============================================
TOTAL_CHECKS=0      # 总检查项目数 - 记录所有验证项目的总数 (Total check items - records total number of all verification items)
PASSED_CHECKS=0     # 通过检查数 - 记录验证成功的项目数量 (Passed checks - records number of successfully verified items)
FAILED_CHECKS=0     # 失败检查数 - 记录验证失败的项目数量 (Failed checks - records number of failed verification items)
WARNING_CHECKS=0    # 警告检查数 - 记录需要注意的项目数量 (Warning checks - records number of items requiring attention)

# ============================================
# 打印结果函数 (Print Result Function)
# ============================================
# 函数名称 (Function Name): print_result
# 功能描述 (Function Description):
#   格式化输出检查结果，支持不同的状态类型，并自动更新统计计数器
#   Format and output check results, support different status types, and automatically update statistical counters
# 参数说明 (Parameter Description):
#   $1 - status: 检查状态 (Check status)
#        - PASS: 检查通过，功能正常 (Check passed, function normal)
#        - FAIL: 检查失败，存在问题需要修复 (Check failed, issues exist and need fixing)
#        - WARN: 检查警告，建议优化但不影响基本功能 (Check warning, optimization recommended but doesn't affect basic functionality)
#        - INFO: 信息性输出，不计入统计 (Informational output, not counted in statistics)
#   $2 - message: 检查项目名称，简洁描述检查内容 (Check item name, concise description of check content)
#   $3 - details: 详细信息，可选参数，提供额外的说明或建议 (Detailed information, optional parameter, provides additional explanation or suggestions)
# 输出格式 (Output Format):
#   - 使用颜色编码和标签标识不同状态 (Use color coding and labels to identify different statuses)
#   - 绿色[PASS]表示通过，红色[FAIL]表示失败，黄色[WARN]表示警告，蓝色[INFO]表示信息 (Green [PASS] for pass, red [FAIL] for fail, yellow [WARN] for warning, blue [INFO] for information)
#   - 详细信息以缩进形式显示在检查项目下方 (Detailed information displayed with indentation below check items)
# 计数器更新 (Counter Updates):
#   - 除INFO类型外，每次调用自动增加TOTAL_CHECKS计数器 (Automatically increment TOTAL_CHECKS counter on each call except for INFO type)
#   - 根据状态类型更新对应的PASSED_CHECKS、FAILED_CHECKS或WARNING_CHECKS (Update corresponding PASSED_CHECKS, FAILED_CHECKS or WARNING_CHECKS based on status type)
# 使用示例 (Usage Examples):
#   print_result "PASS" "备份目录存在" "目录权限: 755, 所有者: backup"
#   print_result "FAIL" "配置文件缺失" "请检查 /opt/backup/config/backup.conf 文件"
#   print_result "WARN" "磁盘空间不足" "当前使用率: 85%, 建议清理旧备份文件"
#   print_result "INFO" "系统信息" "当前时间: $(date)"
# 设计考虑 (Design Considerations):
#   - 支持多语言输出，便于国际化 (Support multilingual output for internationalization)
#   - 颜色编码提高可读性和快速识别 (Color coding improves readability and quick identification)
#   - 统计功能便于生成汇总报告 (Statistical functionality facilitates summary report generation)
# ============================================
print_result() {
    local status="$1"     # 结果类型参数 (Result type parameter)
    local message="$2"    # 检查项描述参数 (Check item description parameter)
    local details="$3"    # 详细说明参数 (Detailed information parameter)
    
    # 增加总检查计数（INFO类型除外，因为INFO仅用于提供信息不代表实际检查）
    # Increment total check count (except INFO type, as INFO is only for providing information, not actual checks)
    if [ "$status" != "INFO" ]; then
        TOTAL_CHECKS=$((TOTAL_CHECKS + 1))
    fi
    
    # 根据结果类型进行不同的处理和显示 (Handle different processing and display based on result type)
    case "$status" in
        "PASS")
            # 显示通过状态 - 绿色标签和文字 (Display pass status - green label and text)
            echo -e "${GREEN}[PASS]${NC} $message"
            if [ -n "$details" ]; then
                echo -e "  ${GREEN}详情: $details${NC}"  # 详细信息也使用绿色显示 (Details also displayed in green)
            fi
            PASSED_CHECKS=$((PASSED_CHECKS + 1))    # 增加通过计数 (Increment passed count)
            ;;
        "FAIL")
            # 显示失败状态 - 红色标签和文字 (Display fail status - red label and text)
            echo -e "${RED}[FAIL]${NC} $message"
            if [ -n "$details" ]; then
                echo -e "  ${RED}详情: $details${NC}"  # 详细信息使用红色突出显示问题 (Details displayed in red to highlight issues)
            fi
            FAILED_CHECKS=$((FAILED_CHECKS + 1))    # 增加失败计数 (Increment failed count)
            ;;
        "WARN")
            # 显示警告状态 - 黄色标签和文字 (Display warning status - yellow label and text)
            echo -e "${YELLOW}[WARN]${NC} $message"
            if [ -n "$details" ]; then
                echo -e "  ${YELLOW}详情: $details${NC}"  # 详细信息使用黄色显示需要注意的内容 (Details displayed in yellow to show content requiring attention)
            fi
            WARNING_CHECKS=$((WARNING_CHECKS + 1))   # 增加警告计数 (Increment warning count)
            ;;
        "INFO")
            # 显示信息状态 - 蓝色标签和文字 (Display info status - blue label and text)
            echo -e "${BLUE}[INFO]${NC} $message"
            if [ -n "$details" ]; then
                echo -e "  ${BLUE}详情: $details${NC}"  # 详细信息使用蓝色显示补充信息 (Details displayed in blue to show supplementary information)
            fi
            # INFO类型不计入统计，仅用于提供额外信息和上下文 (INFO type not counted in statistics, only for providing additional information and context)
            ;;
    esac
}

# ============================================
# 备份目录结构检查函数 (Backup Directory Structure Check Function)
# ============================================
# 函数名称 (Function Name): check_backup_directories
# 功能描述 (Function Description):
#   全面验证备份系统的目录结构、权限和所有权配置，确保备份环境的完整性和安全性
#   Comprehensively verify backup system directory structure, permissions and ownership configuration to ensure backup environment integrity and security
# 检查项目 (Check Items):
#   1. 主备份目录验证 (Main Backup Directory Verification):
#      - 目录存在性检查 (Directory existence check)
#      - 权限设置验证（推荐750或755） (Permission setting verification, recommended 750 or 755)
#      - 所有权配置检查（应为backup用户或root） (Ownership configuration check, should be backup user or root)
#   2. 备份子目录完整性 (Backup Subdirectory Integrity):
#      - daily: 日常备份存储目录 (Daily backup storage directory)
#      - weekly: 周备份存储目录 (Weekly backup storage directory)
#      - monthly: 月备份存储目录 (Monthly backup storage directory)
#      - config: 配置文件备份目录 (Configuration file backup directory)
#      - data: 数据文件备份目录 (Data file backup directory)
#      - database: 数据库备份目录 (Database backup directory)
#      - logs: 备份日志存储目录 (Backup log storage directory)
#      - status: 备份状态文件目录 (Backup status file directory)
#   3. 系统目录验证 (System Directory Verification):
#      - 备份日志目录的存在性和可写性 (Backup log directory existence and writability)
#      - 备份脚本目录的存在性和可访问性 (Backup script directory existence and accessibility)
# 安全考虑 (Security Considerations):
#   - 目录权限应限制为750或755，防止未授权访问 (Directory permissions should be limited to 750 or 755 to prevent unauthorized access)
#   - 所有权应设置为备份用户或root，确保操作权限正确 (Ownership should be set to backup user or root to ensure correct operation permissions)
#   - 敏感备份数据目录应有适当的访问控制 (Sensitive backup data directories should have appropriate access control)
# 故障排除 (Troubleshooting):
#   - 如果主目录不存在，需要创建并设置正确权限 (If main directory doesn't exist, need to create and set correct permissions)
#   - 如果子目录缺失，可能影响特定类型的备份功能 (If subdirectories are missing, may affect specific types of backup functionality)
#   - 权限问题可能导致备份操作失败 (Permission issues may cause backup operations to fail)
# ============================================
check_backup_directories() {
    echo -e "\n${BLUE}=== 备份目录结构检查 (Backup Directory Structure Check) ===${NC}"
    
    # ========================================
    # 主备份目录存在性和配置检查 (Main Backup Directory Existence and Configuration Check)
    # ========================================
    if [ -d "$BACKUP_BASE_DIR" ]; then
        print_result "PASS" "主备份目录存在: $BACKUP_BASE_DIR" "备份根目录已正确创建 (Backup root directory correctly created)"
        
        # 检查主目录权限设置 (Check main directory permission settings)
        # 使用stat命令获取八进制权限表示 (Use stat command to get octal permission representation)
        local dir_perms=$(stat -c "%a" "$BACKUP_BASE_DIR" 2>/dev/null)
        if [ "$dir_perms" = "750" ] || [ "$dir_perms" = "755" ]; then
            print_result "PASS" "备份目录权限: $dir_perms" "权限设置符合安全要求 (Permission settings meet security requirements)"
        else
            print_result "WARN" "备份目录权限: $dir_perms" "建议使用750或755权限以确保安全性 (Recommend using 750 or 755 permissions for security)"
        fi
        
        # 检查主目录所有权配置 (Check main directory ownership configuration)
        # 获取目录所有者用户名 (Get directory owner username)
        local dir_owner=$(stat -c "%U" "$BACKUP_BASE_DIR" 2>/dev/null)
        if [ "$dir_owner" = "$BACKUP_USER" ] || [ "$dir_owner" = "root" ]; then
            print_result "PASS" "备份目录所有者: $dir_owner" "所有者配置正确，具有适当的操作权限 (Owner configuration correct, has appropriate operation permissions)"
        else
            print_result "WARN" "备份目录所有者: $dir_owner" "建议设置为$BACKUP_USER或root以确保权限正确 (Recommend setting to $BACKUP_USER or root to ensure correct permissions)"
        fi
    else
        print_result "FAIL" "主备份目录未找到: $BACKUP_BASE_DIR" "请创建备份根目录并设置适当权限 (Please create backup root directory and set appropriate permissions)"
    fi
    
    # ========================================
    # 备份子目录完整性检查 (Backup Subdirectory Integrity Check)
    # ========================================
    # 定义标准备份子目录列表 (Define standard backup subdirectory list)
    local subdirs=("daily" "weekly" "monthly" "config" "data" "database" "logs" "status")
    echo -e "\n${BLUE}检查备份子目录完整性 (Checking backup subdirectory integrity)...${NC}"
    
    for subdir in "${subdirs[@]}"; do
        local subdir_path="$BACKUP_BASE_DIR/$subdir"
        if [ -d "$subdir_path" ]; then
            print_result "PASS" "备份子目录存在: $subdir" "路径: $subdir_path - 该类型备份功能可用 (Path: $subdir_path - This type of backup functionality available)"
        else
            print_result "WARN" "备份子目录缺失: $subdir" "建议创建: $subdir_path - 可能影响对应的备份功能 (Recommend creating: $subdir_path - May affect corresponding backup functionality)"
        fi
    done
    
    # ========================================
    # 系统相关目录检查 (System Related Directory Check)
    # ========================================
    echo -e "\n${BLUE}检查系统相关目录 (Checking system related directories)...${NC}"
    
    # 检查备份日志目录 (Check backup log directory)
    if [ -d "$BACKUP_LOG_DIR" ]; then
        print_result "PASS" "备份日志目录存在: $BACKUP_LOG_DIR" "日志记录功能可用，便于问题诊断和审计 (Log recording functionality available, facilitates problem diagnosis and auditing)"
    else
        print_result "FAIL" "备份日志目录未找到: $BACKUP_LOG_DIR" "请创建日志目录以启用日志记录功能 (Please create log directory to enable log recording functionality)"
    fi
    
    # 检查备份脚本目录 (Check backup script directory)
    if [ -d "$BACKUP_SCRIPTS_DIR" ]; then
        print_result "PASS" "备份脚本目录存在: $BACKUP_SCRIPTS_DIR" "脚本存储位置正确，备份自动化功能可用 (Script storage location correct, backup automation functionality available)"
    else
        print_result "FAIL" "备份脚本目录未找到: $BACKUP_SCRIPTS_DIR" "请创建脚本目录并部署备份脚本 (Please create script directory and deploy backup scripts)"
    fi
}

# ============================================
# 备份脚本检查函数 (Backup Scripts Check Function)
# ============================================
# 函数名称 (Function Name): check_backup_scripts
# 功能描述 (Function Description):
#   验证备份相关脚本的存在性、可执行性和语法正确性，确保备份自动化功能正常运行
#   Verify existence, executability and syntax correctness of backup-related scripts to ensure backup automation functions properly
# 检查脚本列表 (Check Script List):
#   - backup.sh: 主备份执行脚本，负责执行实际的备份操作 (Main backup execution script, responsible for performing actual backup operations)
#   - restore.sh: 数据恢复脚本，用于从备份中恢复数据 (Data restore script, used to restore data from backups)
#   - verify.sh: 备份验证脚本，检查备份文件的完整性 (Backup verification script, checks backup file integrity)
#   - cleanup.sh: 清理脚本，删除过期的备份文件 (Cleanup script, deletes expired backup files)
#   - backup_monitor.sh: 备份监控脚本，监控备份进程状态 (Backup monitoring script, monitors backup process status)
#   - backup_database.sh: 数据库备份脚本，专门处理数据库备份 (Database backup script, specifically handles database backups)
# 检查项目 (Check Items):
#   1. 文件存在性检查 (File Existence Check):
#      - 验证脚本文件是否存在于指定路径 (Verify script files exist at specified paths)
#      - 确保所有核心备份脚本都已部署 (Ensure all core backup scripts are deployed)
#   2. 执行权限检查 (Execution Permission Check):
#      - 验证脚本是否具有执行权限 (Verify scripts have execution permissions)
#      - 确保脚本可以被系统和用户正常执行 (Ensure scripts can be executed normally by system and users)
#   3. 语法正确性检查 (Syntax Correctness Check):
#      - 使用bash -n进行语法验证 (Use bash -n for syntax validation)
#      - 检测脚本中的语法错误和潜在问题 (Detect syntax errors and potential issues in scripts)
# 安全考虑 (Security Considerations):
#   - 脚本权限应适当设置，避免权限过高的安全风险 (Script permissions should be appropriately set to avoid security risks from excessive permissions)
#   - 确保脚本内容的完整性，防止恶意修改 (Ensure script content integrity, prevent malicious modifications)
#   - 验证脚本的数字签名或校验和（如果适用） (Verify script digital signatures or checksums if applicable)
# 故障排除 (Troubleshooting):
#   - 脚本不存在：检查部署过程，确保脚本正确复制到目标位置 (Script doesn't exist: check deployment process, ensure scripts are correctly copied to target location)
#   - 权限问题：使用chmod +x添加执行权限 (Permission issues: use chmod +x to add execution permissions)
#   - 语法错误：检查脚本内容，修复语法问题 (Syntax errors: check script content, fix syntax issues)
# ============================================
check_backup_scripts() {
    echo -e "\n${BLUE}=== 备份脚本检查 (Backup Scripts Check) ===${NC}"
    
    # 定义需要检查的备份脚本列表 (Define list of backup scripts to check)
    # 这些脚本构成了完整的备份系统自动化功能 (These scripts constitute complete backup system automation functionality)
    local scripts=("backup.sh" "restore.sh" "verify.sh" "cleanup.sh" "backup_monitor.sh" "backup_database.sh")
    
    echo -e "${BLUE}检查 ${#scripts[@]} 个核心备份脚本... (Checking ${#scripts[@]} core backup scripts...)${NC}"
    
    # 逐个检查每个备份脚本 (Check each backup script individually)
    for script in "${scripts[@]}"; do
        local script_path="$BACKUP_SCRIPTS_DIR/$script"
        
        echo -e "\n${BLUE}正在检查脚本: $script (Checking script: $script)${NC}"
        
        # ========================================
        # 脚本文件存在性检查 (Script File Existence Check)
        # ========================================
        if [ -f "$script_path" ]; then
            print_result "PASS" "备份脚本存在: $script" "路径: $script_path - 脚本文件已正确部署 (Path: $script_path - Script file correctly deployed)"
            
            # ========================================
            # 脚本执行权限检查 (Script Execution Permission Check)
            # ========================================
            if [ -x "$script_path" ]; then
                print_result "PASS" "脚本可执行: $script" "执行权限配置正确，脚本可以正常运行 (Execution permissions configured correctly, script can run normally)"
            else
                print_result "FAIL" "脚本不可执行: $script" "建议添加执行权限: chmod +x $script_path (Recommend adding execution permission: chmod +x $script_path)"
            fi
            
            # ========================================
            # 脚本语法正确性检查 (Script Syntax Correctness Check)
            # ========================================
            # 使用bash -n进行语法检查，不实际执行脚本 (Use bash -n for syntax check without actually executing the script)
            if bash -n "$script_path" 2>/dev/null; then
                print_result "PASS" "脚本语法正确: $script" "语法验证通过，脚本结构完整 (Syntax validation passed, script structure complete)"
            else
                print_result "FAIL" "脚本语法错误: $script" "请检查并修复脚本语法错误，可能影响备份功能 (Please check and fix script syntax errors, may affect backup functionality)"
            fi
        else
            print_result "FAIL" "备份脚本未找到: $script" "请确保脚本文件存在于 $script_path，这可能影响备份系统功能 (Please ensure script file exists at $script_path, this may affect backup system functionality)"
        fi
    done
    
    # 提供脚本部署建议 (Provide script deployment recommendations)
    echo -e "\n${BLUE}脚本检查完成。如有缺失脚本，请从备份系统部署包中复制相应文件。"
    echo -e "Script check completed. If scripts are missing, please copy corresponding files from backup system deployment package.${NC}"
}

# ============================================
# 备份配置检查函数 (Backup Configuration Check Function)
# ============================================
# 函数名称 (Function Name): check_backup_configuration
# 功能描述 (Function Description):
#   验证备份配置文件的存在性和关键配置项，确保备份系统配置正确且功能完整
#   Verify existence of backup configuration files and key configuration items to ensure backup system is correctly configured and fully functional
# 检查项目 (Check Items):
#   1. 配置文件验证 (Configuration File Verification):
#      - 主配置文件的存在性和可读性 (Main configuration file existence and readability)
#      - 配置文件格式和语法的正确性 (Configuration file format and syntax correctness)
#   2. 核心功能配置检查 (Core Function Configuration Check):
#      - BACKUP_ENABLED: 备份功能总开关状态 (Backup function master switch status)
#      - COMPRESSION_ENABLED: 压缩功能启用状态 (Compression function enable status)
#      - ENCRYPTION_ENABLED: 加密功能启用状态 (Encryption function enable status)
#   3. 保留策略配置验证 (Retention Policy Configuration Verification):
#      - RETENTION_DAILY: 日备份保留天数设置 (Daily backup retention days setting)
#      - 清理策略的合理性检查 (Cleanup policy rationality check)
#   4. 加密密钥文件验证 (Encryption Key File Verification):
#      - OpenSSL密钥文件的存在性和权限 (OpenSSL key file existence and permissions)
#      - GPG密钥目录的配置状态 (GPG key directory configuration status)
#      - 密钥文件的安全性检查 (Key file security check)
# 配置重要性 (Configuration Importance):
#   - 正确的配置是备份系统正常运行的基础 (Correct configuration is the foundation for backup system normal operation)
#   - 加密配置影响备份数据的安全性 (Encryption configuration affects backup data security)
#   - 保留策略影响存储空间管理和合规性 (Retention policy affects storage space management and compliance)
# 安全考虑 (Security Considerations):
#   - 密钥文件权限应设置为600，仅所有者可读写 (Key file permissions should be set to 600, only owner readable and writable)
#   - 配置文件应防止未授权修改 (Configuration files should prevent unauthorized modifications)
#   - 敏感配置项应适当保护 (Sensitive configuration items should be appropriately protected)
# 故障排除 (Troubleshooting):
#   - 配置文件缺失：从模板创建或重新部署 (Configuration file missing: create from template or redeploy)
#   - 配置项错误：检查语法和值的有效性 (Configuration item errors: check syntax and value validity)
#   - 密钥问题：重新生成或正确部署密钥文件 (Key issues: regenerate or correctly deploy key files)
# ============================================
check_backup_configuration() {
    echo -e "\n${BLUE}=== 备份配置检查 (Backup Configuration Check) ===${NC}"
    
    # ========================================
    # 主配置文件存在性和基本检查 (Main Configuration File Existence and Basic Check)
    # ========================================
    if [ -f "$BACKUP_CONFIG_FILE" ]; then
        print_result "PASS" "备份配置文件存在: $BACKUP_CONFIG_FILE" "配置文件路径正确，可以读取配置信息 (Configuration file path correct, can read configuration information)"
        
        echo -e "\n${BLUE}检查核心配置项... (Checking core configuration items...)${NC}"
        
        # ========================================
        # 备份功能总开关检查 (Backup Function Master Switch Check)
        # ========================================
        if grep -q "BACKUP_ENABLED=true" "$BACKUP_CONFIG_FILE" 2>/dev/null; then
            print_result "PASS" "备份功能已启用" "备份功能处于活动状态，系统将执行备份任务 (Backup function active, system will execute backup tasks)"
        else
            print_result "WARN" "备份功能可能已禁用或未配置" "请检查BACKUP_ENABLED配置项，确保设置为true (Please check BACKUP_ENABLED configuration item, ensure it's set to true)"
        fi
        
        # ========================================
        # 压缩功能配置检查 (Compression Function Configuration Check)
        # ========================================
        if grep -q "COMPRESSION_ENABLED=true" "$BACKUP_CONFIG_FILE" 2>/dev/null; then
            print_result "PASS" "压缩功能已启用" "备份文件将被压缩以节省存储空间和传输时间 (Backup files will be compressed to save storage space and transfer time)"
        else
            print_result "INFO" "压缩功能已禁用" "备份文件不会被压缩，将保持原始格式 (Backup files will not be compressed, will maintain original format)"
        fi
        
        # ========================================
        # 加密功能配置检查 (Encryption Function Configuration Check)
        # ========================================
        if grep -q "ENCRYPTION_ENABLED=true" "$BACKUP_CONFIG_FILE" 2>/dev/null; then
            print_result "PASS" "加密功能已启用" "备份文件将被加密保护，提高数据安全性 (Backup files will be encrypted for protection, improving data security)"
        else
            print_result "INFO" "加密功能已禁用" "备份文件不会被加密，请评估安全风险 (Backup files will not be encrypted, please assess security risks)"
        fi
        
        # ========================================
        # 保留策略配置检查 (Retention Policy Configuration Check)
        # ========================================
        echo -e "\n${BLUE}检查保留策略配置... (Checking retention policy configuration...)${NC}"
        
        local daily_retention=$(grep "RETENTION_DAILY=" "$BACKUP_CONFIG_FILE" | cut -d'=' -f2 2>/dev/null || echo "unknown")
        if [ "$daily_retention" != "unknown" ] && [ "$daily_retention" -gt 0 ] 2>/dev/null; then
            print_result "PASS" "日备份保留期已配置: $daily_retention 天" "旧备份将按策略自动清理，避免存储空间耗尽 (Old backups will be automatically cleaned according to policy, avoiding storage space exhaustion)"
        else
            print_result "WARN" "日备份保留期未配置或无效" "建议配置RETENTION_DAILY参数以管理存储空间 (Recommend configuring RETENTION_DAILY parameter to manage storage space)"
        fi
    else
        print_result "FAIL" "备份配置文件未找到: $BACKUP_CONFIG_FILE" "请创建并配置备份配置文件，这是备份系统运行的必要条件 (Please create and configure backup configuration file, this is necessary for backup system operation)"
    fi
    
    # ========================================
    # 加密相关密钥文件检查 (Encryption Related Key File Check)
    # ========================================
    echo -e "\n${BLUE}检查加密密钥配置... (Checking encryption key configuration...)${NC}"
    
    # 定义密钥文件路径 (Define key file paths)
    local openssl_key="/etc/backup/backup.key"    # OpenSSL加密密钥文件 (OpenSSL encryption key file)
    local gpg_key_dir="/etc/backup/gpg"           # GPG密钥目录 (GPG key directory)
    
    # ========================================
    # OpenSSL加密密钥检查 (OpenSSL Encryption Key Check)
    # ========================================
    if [ -f "$openssl_key" ]; then
        print_result "PASS" "OpenSSL加密密钥存在" "SSL加密功能可用，支持对称加密备份 (SSL encryption functionality available, supports symmetric encryption backup)"
        
        # 检查密钥文件权限安全性 (Check key file permission security)
        local key_perms=$(stat -c "%a" "$openssl_key" 2>/dev/null)
        if [ "$key_perms" = "600" ]; then
            print_result "PASS" "加密密钥权限: $key_perms" "密钥文件权限安全，仅所有者可访问 (Key file permissions secure, only owner can access)"
        else
            print_result "WARN" "加密密钥权限: $key_perms (应为600)" "建议设置更安全的权限: chmod 600 $openssl_key (Recommend setting more secure permissions: chmod 600 $openssl_key)"
        fi
    else
        print_result "INFO" "OpenSSL加密密钥未找到 (可能未配置)" "SSL加密功能不可用，如需加密请配置密钥 (SSL encryption functionality unavailable, please configure key if encryption needed)"
    fi
    
    # ========================================
    # GPG密钥目录检查 (GPG Key Directory Check)
    # ========================================
    if [ -d "$gpg_key_dir" ]; then
        print_result "PASS" "GPG密钥目录存在" "GPG加密功能可用，支持公钥加密备份 (GPG encryption functionality available, supports public key encryption backup)"
    else
        print_result "INFO" "GPG密钥目录未找到 (可能未配置)" "GPG加密功能不可用，如需GPG加密请配置密钥目录 (GPG encryption functionality unavailable, please configure key directory if GPG encryption needed)"
    fi
}

# ============================================
# 备份用户和权限检查函数 (Backup User and Permission Check Function)
# ============================================
# 函数名称 (Function Name): check_backup_user
# 功能描述 (Function Description):
#   验证备份用户的存在性、主目录、shell和权限配置，确保备份系统具有适当的用户权限
#   Verify backup user existence, home directory, shell and permission configuration to ensure backup system has appropriate user permissions
# 检查项目 (Check Items):
#   1. 用户账户验证 (User Account Verification):
#      - 备份专用用户账户的存在性验证 (Backup dedicated user account existence verification)
#      - 用户ID和组ID的正确性检查 (User ID and group ID correctness check)
#      - 用户账户状态的有效性验证 (User account status validity verification)
#   2. 用户环境检查 (User Environment Check):
#      - 用户主目录的存在性和可访问性 (User home directory existence and accessibility)
#      - 用户默认shell的类型和适用性 (User default shell type and applicability)
#      - 用户环境变量的配置状态 (User environment variable configuration status)
#   3. 权限配置验证 (Permission Configuration Verification):
#      - sudo权限的配置和范围检查 (sudo permission configuration and scope check)
#      - 文件系统访问权限的验证 (File system access permission verification)
#      - 特殊权限需求的满足情况 (Special permission requirement satisfaction)
#   4. 特殊用户处理 (Special User Handling):
#      - root用户使用情况的特殊处理 (Special handling for root user usage)
#      - 系统用户和服务用户的区分 (Distinction between system users and service users)
# 安全考虑 (Security Considerations):
#   - 备份用户应具有最小必要权限原则 (Backup user should follow principle of least privilege)
#   - 避免使用root用户进行日常备份操作 (Avoid using root user for routine backup operations)
#   - sudo权限应精确配置，避免过度授权 (sudo permissions should be precisely configured, avoiding over-authorization)
#   - 用户主目录权限应适当保护 (User home directory permissions should be appropriately protected)
# 最佳实践 (Best Practices):
#   - 创建专用的备份用户账户 (Create dedicated backup user account)
#   - 配置适当的sudo权限而非完全root权限 (Configure appropriate sudo permissions instead of full root privileges)
#   - 定期审查用户权限和访问范围 (Regularly review user permissions and access scope)
#   - 使用密钥认证而非密码认证 (Use key authentication instead of password authentication)
# 故障排除 (Troubleshooting):
#   - 用户不存在：使用useradd创建用户 (User doesn't exist: use useradd to create user)
#   - 权限不足：配置sudo或调整文件权限 (Insufficient permissions: configure sudo or adjust file permissions)
#   - 主目录问题：检查挂载点和权限设置 (Home directory issues: check mount points and permission settings)
# ============================================
check_backup_user() {
    echo -e "\n${BLUE}=== 备份用户和权限检查 (Backup User and Permission Check) ===${NC}"
    
    # ========================================
    # 备份用户存在性验证 (Backup User Existence Verification)
    # ========================================
    if id "$BACKUP_USER" >/dev/null 2>&1; then
        print_result "PASS" "备份用户存在: $BACKUP_USER" "用户账户已正确创建，可以执行备份操作 (User account correctly created, can execute backup operations)"
        
        echo -e "\n${BLUE}检查用户环境配置... (Checking user environment configuration...)${NC}"
        
        # ========================================
        # 用户主目录检查 (User Home Directory Check)
        # ========================================
        local user_home=$(getent passwd "$BACKUP_USER" | cut -d: -f6)
        if [ -d "$user_home" ]; then
            print_result "PASS" "备份用户主目录存在: $user_home" "主目录路径有效且可访问，用户环境完整 (Home directory path valid and accessible, user environment complete)"
            
            # 检查主目录权限 (Check home directory permissions)
            local home_perms=$(stat -c "%a" "$user_home" 2>/dev/null)
            if [ "$home_perms" = "750" ] || [ "$home_perms" = "755" ]; then
                print_result "PASS" "主目录权限: $home_perms" "主目录权限设置合理 (Home directory permissions reasonably set)"
            else
                print_result "WARN" "主目录权限: $home_perms" "建议设置为750或755以确保安全性 (Recommend setting to 750 or 755 for security)"
            fi
        else
            print_result "WARN" "备份用户主目录未找到: $user_home" "建议创建用户主目录: mkdir -p $user_home && chown $BACKUP_USER:$BACKUP_USER $user_home (Recommend creating user home directory: mkdir -p $user_home && chown $BACKUP_USER:$BACKUP_USER $user_home)"
        fi
        
        # ========================================
        # 用户Shell配置检查 (User Shell Configuration Check)
        # ========================================
        local user_shell=$(getent passwd "$BACKUP_USER" | cut -d: -f7)
        if [ "$user_shell" = "/bin/bash" ] || [ "$user_shell" = "/bin/sh" ]; then
            print_result "PASS" "备份用户shell: $user_shell" "Shell环境适合执行备份脚本 (Shell environment suitable for executing backup scripts)"
        elif [ "$user_shell" = "/bin/false" ] || [ "$user_shell" = "/sbin/nologin" ]; then
            print_result "WARN" "备份用户shell: $user_shell" "受限shell可能影响脚本执行，考虑使用/bin/bash (Restricted shell may affect script execution, consider using /bin/bash)"
        else
            print_result "INFO" "备份用户shell: $user_shell" "当前用户默认shell环境 (Current user default shell environment)"
        fi
    else
        # ========================================
        # 特殊用户情况处理 (Special User Situation Handling)
        # ========================================
        if [ "$BACKUP_USER" = "root" ]; then
            print_result "INFO" "使用root用户进行备份" "具有系统最高权限，但不符合最小权限原则 (Has highest system privileges, but doesn't follow principle of least privilege)"
        else
            print_result "FAIL" "备份用户未找到: $BACKUP_USER" "请创建备份专用用户账户: useradd -m -s /bin/bash $BACKUP_USER (Please create dedicated backup user account: useradd -m -s /bin/bash $BACKUP_USER)"
        fi
    fi
    
    # ========================================
    # sudo权限配置检查 (sudo Permission Configuration Check)
    # ========================================
    echo -e "\n${BLUE}检查权限配置... (Checking permission configuration...)${NC}"
    
    if [ "$BACKUP_USER" != "root" ]; then
        # 检查sudo权限配置 (Check sudo permission configuration)
        if sudo -l -U "$BACKUP_USER" 2>/dev/null | grep -q "ALL"; then
            print_result "PASS" "备份用户具有sudo权限" "可以执行需要特权的备份操作，如访问系统文件 (Can execute privileged backup operations, such as accessing system files)"
        else
            print_result "WARN" "备份用户可能缺少必要的sudo权限" "某些备份操作可能受限，建议配置适当的sudo权限 (Some backup operations may be restricted, recommend configuring appropriate sudo permissions)"
        fi
        
        # 检查用户组成员身份 (Check user group membership)
        local user_groups=$(groups "$BACKUP_USER" 2>/dev/null | cut -d: -f2)
        if echo "$user_groups" | grep -q "backup\|admin\|wheel"; then
            print_result "PASS" "备份用户属于管理组" "用户组成员身份有助于权限管理 (User group membership helps with permission management)"
        else
            print_result "INFO" "备份用户组: $user_groups" "当前用户组成员身份 (Current user group membership)"
        fi
    else
        print_result "WARN" "使用root用户执行备份" "建议创建专用备份用户以提高安全性 (Recommend creating dedicated backup user for improved security)"
    fi
}

# ============================================
# 备份Cron作业检查函数 (Backup Cron Jobs Check Function)
# ============================================
# 函数名称 (Function Name): check_cron_jobs
# 功能描述 (Function Description):
#   验证cron服务状态和备份相关的定时任务配置，确保自动化备份系统正常运行
#   Verify cron service status and backup-related scheduled task configuration to ensure automated backup system runs normally
# 检查项目 (Check Items):
#   1. Cron服务状态验证 (Cron Service Status Verification):
#      - cron/crond服务的运行状态检查 (cron/crond service running status check)
#      - 服务启动状态和自启动配置 (Service startup status and auto-start configuration)
#      - 服务进程的健康状态监控 (Service process health status monitoring)
#   2. 定时任务配置检查 (Scheduled Task Configuration Check):
#      - 备份用户的crontab配置验证 (Backup user crontab configuration verification)
#      - 定时任务语法和格式的正确性 (Scheduled task syntax and format correctness)
#      - 任务执行时间的合理性评估 (Task execution time rationality assessment)
#   3. 备份频率策略验证 (Backup Frequency Strategy Verification):
#      - 日备份作业的配置和调度 (Daily backup job configuration and scheduling)
#      - 周备份作业的配置和调度 (Weekly backup job configuration and scheduling)
#      - 月备份作业的配置和调度 (Monthly backup job configuration and scheduling)
#   4. 任务完整性检查 (Task Completeness Check):
#      - 备份脚本路径的有效性验证 (Backup script path validity verification)
#      - 清理和维护任务的配置状态 (Cleanup and maintenance task configuration status)
#      - 监控和报告任务的设置情况 (Monitoring and reporting task setup status)
# 调度策略 (Scheduling Strategy):
#   - 日备份：通常在业务低峰期执行 (Daily backup: usually executed during low business peak)
#   - 周备份：在周末或业务最低峰期执行 (Weekly backup: executed on weekends or lowest business peak)
#   - 月备份：月初或月末执行完整备份 (Monthly backup: execute full backup at beginning or end of month)
# 时间配置建议 (Time Configuration Recommendations):
#   - 避免在系统维护时间执行备份 (Avoid executing backups during system maintenance time)
#   - 考虑网络带宽和存储I/O负载 (Consider network bandwidth and storage I/O load)
#   - 错开不同类型备份的执行时间 (Stagger execution times of different backup types)
# 故障排除 (Troubleshooting):
#   - Cron服务未运行：systemctl start cron (Cron service not running: systemctl start cron)
#   - 任务未配置：使用crontab -e添加任务 (Tasks not configured: use crontab -e to add tasks)
#   - 权限问题：检查用户crontab访问权限 (Permission issues: check user crontab access permissions)
# ============================================
check_cron_jobs() {
    echo -e "\n${BLUE}=== 备份Cron作业检查 (Backup Cron Jobs Check) ===${NC}"
    
    # ========================================
    # Cron服务状态验证 (Cron Service Status Verification)
    # ========================================
    if systemctl is-active --quiet cron || systemctl is-active --quiet crond; then
        print_result "PASS" "Cron服务正在运行" "定时任务调度服务状态正常，可以执行自动化备份 (Scheduled task scheduling service status normal, can execute automated backups)"
        
        # 检查cron服务是否设置为自启动 (Check if cron service is set to auto-start)
        if systemctl is-enabled --quiet cron || systemctl is-enabled --quiet crond; then
            print_result "PASS" "Cron服务已设置自启动" "系统重启后服务将自动启动 (Service will auto-start after system reboot)"
        else
            print_result "WARN" "Cron服务未设置自启动" "建议启用自启动: systemctl enable cron (Recommend enabling auto-start: systemctl enable cron)"
        fi
    else
        print_result "FAIL" "Cron服务未运行" "请启动cron或crond服务: systemctl start cron (Please start cron or crond service: systemctl start cron)"
    fi
    
    echo -e "\n${BLUE}检查定时任务配置... (Checking scheduled task configuration...)${NC}"
    
    # ========================================
    # 备份用户定时任务配置检查 (Backup User Scheduled Task Configuration Check)
    # ========================================
    local cron_jobs=$(crontab -u "$BACKUP_USER" -l 2>/dev/null | grep -v "^#" | grep "backup.sh" || echo "")
    
    if [ -n "$cron_jobs" ]; then
        local job_count=$(echo "$cron_jobs" | wc -l)
        print_result "PASS" "备份cron作业已配置 ($job_count 个作业)" "自动化备份任务设置完成，系统将按计划执行备份 (Automated backup tasks configured, system will execute backups as scheduled)"
        
        echo -e "\n${BLUE}检查备份频率策略... (Checking backup frequency strategy...)${NC}"
        
        # ========================================
        # 日备份作业配置检查 (Daily Backup Job Configuration Check)
        # ========================================
        if echo "$cron_jobs" | grep -q "daily"; then
            print_result "PASS" "日备份作业已配置" "每日自动备份功能可用，确保数据的日常保护 (Daily automatic backup functionality available, ensuring daily data protection)"
        else
            print_result "WARN" "未找到日备份作业" "建议配置每日备份任务以确保数据安全 (Recommend configuring daily backup tasks to ensure data security)"
        fi
        
        # ========================================
        # 周备份作业配置检查 (Weekly Backup Job Configuration Check)
        # ========================================
        if echo "$cron_jobs" | grep -q "weekly"; then
            print_result "PASS" "周备份作业已配置" "每周自动备份功能可用，提供中期数据保护 (Weekly automatic backup functionality available, providing medium-term data protection)"
        else
            print_result "WARN" "未找到周备份作业" "建议配置每周备份任务以增强数据保护 (Recommend configuring weekly backup tasks to enhance data protection)"
        fi
        
        # ========================================
        # 月备份作业配置检查 (Monthly Backup Job Configuration Check)
        # ========================================
        if echo "$cron_jobs" | grep -q "monthly"; then
            print_result "PASS" "月备份作业已配置" "每月自动备份功能可用，提供长期数据归档 (Monthly automatic backup functionality available, providing long-term data archiving)"
        else
            print_result "WARN" "未找到月备份作业" "建议配置每月备份任务以实现长期数据保留 (Recommend configuring monthly backup tasks for long-term data retention)"
        fi
        
        # ========================================
        # 定时任务详细信息显示 (Scheduled Task Details Display)
        # ========================================
        echo -e "\n${BLUE}当前配置的备份任务: (Currently configured backup tasks:)${NC}"
        echo "$cron_jobs" | while read -r job; do
            if [ -n "$job" ]; then
                print_result "INFO" "定时任务: $job" "备份任务调度配置 (Backup task scheduling configuration)"
            fi
        done
    else
        print_result "FAIL" "用户 $BACKUP_USER 未找到备份cron作业" "请配置自动化备份定时任务，示例: 0 2 * * * /path/to/backup.sh daily (Please configure automated backup scheduled tasks, example: 0 2 * * * /path/to/backup.sh daily)"
    fi
    
    # ========================================
    # 系统级定时任务检查 (System-level Scheduled Task Check)
    # ========================================
    echo -e "\n${BLUE}检查系统级备份任务... (Checking system-level backup tasks...)${NC}"
    
    # 检查/etc/cron.d/目录中的备份相关任务 (Check backup-related tasks in /etc/cron.d/ directory)
    if ls /etc/cron.d/*backup* 2>/dev/null | head -1 >/dev/null; then
        print_result "PASS" "发现系统级备份任务" "系统级定时任务配置存在 (System-level scheduled task configuration exists)"
    else
        print_result "INFO" "未发现系统级备份任务" "备份任务可能仅在用户级别配置 (Backup tasks may only be configured at user level)"
    fi
}
    
    # ========================================
    # 清理作业配置检查 (Cleanup Job Configuration Check)
    # ========================================
    echo -e "\n${BLUE}检查维护任务配置... (Checking maintenance task configuration...)${NC}"
    
    local cleanup_jobs=$(crontab -u "$BACKUP_USER" -l 2>/dev/null | grep -v "^#" | grep "cleanup.sh" || echo "")
    if [ -n "$cleanup_jobs" ]; then
        print_result "PASS" "清理cron作业已配置" "自动清理旧备份功能可用，防止存储空间耗尽 (Automatic cleanup of old backups available, preventing storage space exhaustion)"
    else
        print_result "WARN" "未找到清理cron作业" "建议配置定期清理任务以管理存储空间，示例: 0 3 * * 0 /path/to/cleanup.sh (Recommend configuring periodic cleanup tasks to manage storage space, example: 0 3 * * 0 /path/to/cleanup.sh)"
    fi
    
    # ========================================
    # 验证作业配置检查 (Verification Job Configuration Check)
    # ========================================
    local verify_jobs=$(crontab -u "$BACKUP_USER" -l 2>/dev/null | grep -v "^#" | grep "verify.sh" || echo "")
    if [ -n "$verify_jobs" ]; then
        print_result "PASS" "验证cron作业已配置" "自动验证备份完整性功能可用，确保备份质量 (Automatic backup integrity verification available, ensuring backup quality)"
    else
        print_result "WARN" "未找到验证cron作业" "建议配置定期验证任务以确保备份可靠性，示例: 0 4 * * 1 /path/to/verify.sh (Recommend configuring periodic verification tasks to ensure backup reliability, example: 0 4 * * 1 /path/to/verify.sh)"
    fi
}

# ============================================
# 备份Systemd服务检查函数 (Backup Systemd Services Check Function)
# ============================================
# 函数名称 (Function Name): check_systemd_services
# 功能描述 (Function Description):
#   验证备份相关的systemd服务和定时器状态，确保现代化的服务管理和调度机制正常运行
#   Verify backup-related systemd services and timer status to ensure modern service management and scheduling mechanisms run normally
# 检查项目 (Check Items):
#   1. 服务单元文件验证 (Service Unit File Verification):
#      - 备份监控服务单元文件的存在性 (Backup monitoring service unit file existence)
#      - 服务配置文件的完整性和语法正确性 (Service configuration file completeness and syntax correctness)
#      - 服务依赖关系的正确配置 (Service dependency relationship correct configuration)
#   2. 服务状态检查 (Service Status Check):
#      - 服务的启用状态检查（开机自启动） (Service enable status check - auto-start on boot)
#      - 服务的当前运行状态检查 (Service current running status check)
#      - 服务的健康状态和错误日志 (Service health status and error logs)
#   3. 定时器单元验证 (Timer Unit Verification):
#      - systemd定时器单元的配置和状态 (systemd timer unit configuration and status)
#      - 定时器调度策略的正确性验证 (Timer scheduling strategy correctness verification)
#      - 定时器与服务的关联关系检查 (Timer and service association relationship check)
#   4. 现代化调度优势 (Modern Scheduling Advantages):
#      - 相比传统cron的优势评估 (Advantages assessment compared to traditional cron)
#      - 日志记录和监控能力验证 (Logging and monitoring capability verification)
#      - 依赖管理和故障恢复机制 (Dependency management and failure recovery mechanism)
# Systemd vs Cron对比 (Systemd vs Cron Comparison):
#   - Systemd优势：更好的日志记录、依赖管理、故障恢复 (Systemd advantages: better logging, dependency management, failure recovery)
#   - 统一的服务管理界面和状态监控 (Unified service management interface and status monitoring)
#   - 更精确的时间控制和资源管理 (More precise time control and resource management)
# 配置建议 (Configuration Recommendations):
#   - 优先使用systemd定时器而非cron (Prefer systemd timers over cron)
#   - 配置适当的服务依赖关系 (Configure appropriate service dependencies)
#   - 启用服务日志记录和监控 (Enable service logging and monitoring)
# 故障排除 (Troubleshooting):
#   - 服务未找到：检查安装和配置 (Service not found: check installation and configuration)
#   - 服务启动失败：查看systemctl status和journalctl日志 (Service startup failure: check systemctl status and journalctl logs)
#   - 定时器不工作：验证定时器配置和服务关联 (Timer not working: verify timer configuration and service association)
# ============================================
check_systemd_services() {
    echo -e "\n${BLUE}=== 备份Systemd服务检查 (Backup Systemd Services Check) ===${NC}"
    
    # ========================================
    # 备份监控服务单元检查 (Backup Monitoring Service Unit Check)
    # ========================================
    if systemctl list-unit-files | grep -q "backup-monitor.service"; then
        print_result "PASS" "备份监控服务单元存在" "systemd服务配置文件已正确安装，支持现代化服务管理 (systemd service configuration file correctly installed, supports modern service management)"
        
        # 检查服务启用状态 (Check service enable status)
        if systemctl is-enabled --quiet backup-monitor.service 2>/dev/null; then
            print_result "PASS" "备份监控服务已启用" "服务将在系统启动时自动启动，确保持续监控 (Service will auto-start on system boot, ensuring continuous monitoring)"
        else
            print_result "WARN" "备份监控服务未启用" "建议启用服务以确保开机自启动: systemctl enable backup-monitor.service (Recommend enabling service for auto-start on boot: systemctl enable backup-monitor.service)"
        fi
        
        # 检查服务当前运行状态 (Check service current running status)
        if systemctl is-active --quiet backup-monitor.service; then
            print_result "PASS" "备份监控服务正在运行" "服务状态正常，正在执行监控任务 (Service status normal, executing monitoring tasks)"
        else
            print_result "INFO" "备份监控服务未运行" "服务可能按需启动或需要手动启动 (Service may start on-demand or require manual start)"
        fi
    else
        print_result "WARN" "备份监控服务单元未找到" "可能未安装或配置此服务，考虑使用传统cron作业 (May not be installed or configured, consider using traditional cron jobs)"
    fi
    
    echo -e "\n${BLUE}检查systemd定时器配置... (Checking systemd timer configuration...)${NC}"
    
    # ========================================
    # 备份监控定时器单元检查 (Backup Monitoring Timer Unit Check)
    # ========================================
    if systemctl list-unit-files | grep -q "backup-monitor.timer"; then
        print_result "PASS" "备份监控定时器单元存在" "systemd定时器配置文件已正确安装，提供现代化调度功能 (systemd timer configuration file correctly installed, providing modern scheduling functionality)"
        
        # 检查定时器运行状态 (Check timer running status)
        if systemctl is-active --quiet backup-monitor.timer; then
            print_result "PASS" "备份监控定时器正在运行" "定时器状态正常，按计划执行任务，优于传统cron (Timer status normal, executing tasks as scheduled, superior to traditional cron)"
        else
            print_result "WARN" "备份监控定时器未运行" "建议启动定时器: systemctl start backup-monitor.timer (Recommend starting timer: systemctl start backup-monitor.timer)"
        fi
        
        # 检查定时器启用状态 (Check timer enable status)
        if systemctl is-enabled --quiet backup-monitor.timer; then
            print_result "PASS" "备份监控定时器已启用" "定时器将在系统启动时自动启动，确保调度连续性 (Timer will auto-start on system boot, ensuring scheduling continuity)"
        else
            print_result "WARN" "备份监控定时器未启用" "建议启用定时器以确保开机自启动: systemctl enable backup-monitor.timer (Recommend enabling timer for auto-start on boot: systemctl enable backup-monitor.timer)"
        fi
        
        # 显示定时器下次执行时间 (Show timer next execution time)
        local next_run=$(systemctl list-timers backup-monitor.timer --no-pager 2>/dev/null | grep backup-monitor.timer | awk '{print $1, $2}')
        if [ -n "$next_run" ]; then
            print_result "INFO" "定时器下次执行: $next_run" "定时器调度信息 (Timer scheduling information)"
        fi
    else
        print_result "WARN" "备份监控定时器单元未找到" "可能未安装或配置此定时器，建议使用systemd定时器替代cron (May not be installed or configured, recommend using systemd timer instead of cron)"
    fi
    
    # ========================================
    # 其他备份相关服务检查 (Other Backup-related Services Check)
    # ========================================
    echo -e "\n${BLUE}检查其他备份服务... (Checking other backup services...)${NC}"
    
    # 检查是否有其他备份相关的systemd服务 (Check for other backup-related systemd services)
    local backup_services=$(systemctl list-unit-files | grep -E "backup|restore" | grep "\.service" | awk '{print $1}' || echo "")
    if [ -n "$backup_services" ]; then
        echo "$backup_services" | while read -r service; do
            if [ -n "$service" ]; then
                print_result "INFO" "发现备份相关服务: $service" "系统中存在其他备份服务配置 (Other backup service configuration exists in system)"
            fi
        done
    else
        print_result "INFO" "未发现其他备份相关服务" "系统可能主要依赖cron作业进行备份调度 (System may primarily rely on cron jobs for backup scheduling)"
    fi
}

# ============================================
# 日志轮转配置检查函数 (Log Rotation Configuration Check Function)
# ============================================
# 函数名称 (Function Name): check_log_rotation
# 功能描述 (Function Description):
#   验证备份系统的日志轮转配置和日志文件状态，确保日志管理的有效性和系统存储的合理使用
#   Verify backup system log rotation configuration and log file status to ensure log management effectiveness and reasonable system storage usage
# 检查项目 (Check Items):
#   1. Logrotate配置验证 (Logrotate Configuration Verification):
#      - logrotate配置文件的存在性验证 (logrotate configuration file existence verification)
#      - 配置文件的语法正确性检查 (Configuration file syntax correctness check)
#      - 轮转策略的合理性评估 (Rotation strategy reasonableness assessment)
#      - 压缩和保留策略的有效性 (Compression and retention strategy effectiveness)
#   2. 日志文件状态检查 (Log File Status Check):
#      - 备份相关日志文件的存在性验证 (Backup-related log file existence verification)
#      - 日志文件的权限配置安全性验证 (Log file permission configuration security verification)
#      - 日志文件大小和增长趋势监控 (Log file size and growth trend monitoring)
#      - 日志文件的可读性和完整性检查 (Log file readability and integrity check)
#   3. 轮转策略评估 (Rotation Strategy Assessment):
#      - 日志轮转频率的合理性 (Log rotation frequency reasonableness)
#      - 历史日志的保留期限设置 (Historical log retention period settings)
#      - 压缩算法和存储效率 (Compression algorithm and storage efficiency)
#      - 轮转触发条件的适当性 (Rotation trigger condition appropriateness)
# 日志管理重要性 (Log Management Importance):
#   - 防止日志文件无限增长占用磁盘空间 (Prevent log files from growing infinitely and consuming disk space)
#   - 保持系统性能和稳定性 (Maintain system performance and stability)
#   - 便于问题排查和历史追溯 (Facilitate problem troubleshooting and historical tracing)
#   - 符合安全审计和合规要求 (Meet security audit and compliance requirements)
# 配置建议 (Configuration Recommendations):
#   - 根据日志产生量设置合适的轮转频率 (Set appropriate rotation frequency based on log generation volume)
#   - 启用压缩以节省存储空间 (Enable compression to save storage space)
#   - 设置合理的历史日志保留期限 (Set reasonable historical log retention period)
#   - 配置日志文件权限以确保安全性 (Configure log file permissions to ensure security)
# 故障排除 (Troubleshooting):
#   - 配置文件语法错误：使用logrotate -d检查 (Configuration file syntax error: use logrotate -d to check)
#   - 轮转不工作：检查cron任务和权限 (Rotation not working: check cron tasks and permissions)
#   - 日志文件权限问题：调整文件所有者和权限 (Log file permission issues: adjust file owner and permissions)
# ============================================
check_log_rotation() {
    echo -e "\n${BLUE}=== 日志轮转检查 (Log Rotation Check) ===${NC}"
    
    # ========================================
    # Logrotate配置文件检查 (Logrotate Configuration File Check)
    # ========================================
    local logrotate_config="/etc/logrotate.d/backup"
    if [ -f "$logrotate_config" ]; then
        print_result "PASS" "备份日志轮转配置存在" "配置文件路径: $logrotate_config，支持自动日志管理 (Configuration file path: $logrotate_config, supports automatic log management)"
        
        # 验证logrotate配置文件的语法正确性 (Verify logrotate configuration file syntax correctness)
        if logrotate -d "$logrotate_config" >/dev/null 2>&1; then
            print_result "PASS" "日志轮转配置有效" "配置文件语法检查通过，轮转策略将正常执行 (Configuration file syntax check passed, rotation strategy will execute normally)"
        else
            print_result "FAIL" "日志轮转配置有错误" "请检查配置文件语法: logrotate -d $logrotate_config (Please check configuration file syntax: logrotate -d $logrotate_config)"
        fi
        
        # 检查配置文件内容的关键设置 (Check key settings in configuration file content)
        if grep -q "compress" "$logrotate_config" 2>/dev/null; then
            print_result "PASS" "启用日志压缩" "压缩功能有助于节省存储空间 (Compression feature helps save storage space)"
        else
            print_result "INFO" "未启用日志压缩" "建议启用压缩以节省磁盘空间 (Recommend enabling compression to save disk space)"
        fi
        
        # 检查轮转频率设置 (Check rotation frequency settings)
        if grep -qE "(daily|weekly|monthly)" "$logrotate_config" 2>/dev/null; then
            local rotation_freq=$(grep -oE "(daily|weekly|monthly)" "$logrotate_config" | head -1)
            print_result "PASS" "轮转频率: $rotation_freq" "日志轮转频率配置合理 (Log rotation frequency configuration reasonable)"
        else
            print_result "WARN" "未明确轮转频率" "建议明确设置轮转频率 (Recommend explicitly setting rotation frequency)"
        fi
    else
        print_result "WARN" "备份日志轮转配置未找到" "建议配置日志轮转以管理日志文件大小，防止磁盘空间耗尽 (Recommend configuring log rotation to manage log file size and prevent disk space exhaustion)"
        print_result "INFO" "创建logrotate配置示例" "可参考: /etc/logrotate.d/rsyslog 创建备份日志轮转配置 (Reference: /etc/logrotate.d/rsyslog to create backup log rotation configuration)"
    fi
    
    echo -e "\n${BLUE}检查备份日志文件状态... (Checking backup log file status...)${NC}"
    
    # ========================================
    # 备份日志文件状态检查 (Backup Log File Status Check)
    # ========================================
    # 定义需要检查的备份相关日志文件列表 (Define list of backup-related log files to check)
    local log_files=("backup.log" "backup_monitor.log" "database_backup.log" "restore.log" "verify.log" "cleanup.log")
    
    # 逐个检查每个日志文件的状态和权限 (Check status and permissions of each log file individually)
    for log_file in "${log_files[@]}"; do
        local log_path="$BACKUP_LOG_DIR/$log_file"
        if [ -f "$log_path" ]; then
            print_result "PASS" "日志文件存在: $log_file" "路径: $log_path，记录备份操作历史 (Path: $log_path, records backup operation history)"
            
            # 检查日志文件的权限设置是否安全合理 (Check if log file permission settings are secure and reasonable)
            local log_perms=$(stat -c "%a" "$log_path" 2>/dev/null)
            if [ "$log_perms" = "640" ] || [ "$log_perms" = "644" ]; then
                print_result "PASS" "日志文件权限: $log_file ($log_perms)" "权限设置安全合理，符合最佳实践 (Permission settings secure and reasonable, following best practices)"
            else
                print_result "WARN" "日志文件权限: $log_file ($log_perms)" "建议使用640或644权限以确保安全性 (Recommend using 640 or 644 permissions to ensure security)"
            fi
            
            # 检查日志文件大小 (Check log file size)
            local log_size=$(stat -c "%s" "$log_path" 2>/dev/null)
            local log_size_mb=$((log_size / 1024 / 1024))
            if [ $log_size_mb -gt 100 ]; then
                print_result "WARN" "日志文件较大: $log_file (${log_size_mb}MB)" "建议检查日志轮转配置 (Recommend checking log rotation configuration)"
            elif [ $log_size_mb -gt 10 ]; then
                print_result "INFO" "日志文件大小: $log_file (${log_size_mb}MB)" "文件大小适中 (File size moderate)"
            else
                print_result "PASS" "日志文件大小: $log_file (${log_size_mb}MB)" "文件大小正常 (File size normal)"
            fi
        else
            print_result "INFO" "日志文件未找到: $log_file" "日志文件将在首次运行相应操作时创建 (Log file will be created when corresponding operation runs for the first time)"
        fi
    done
    
    # ========================================
    # 日志目录权限检查 (Log Directory Permission Check)
    # ========================================
    if [ -d "$BACKUP_LOG_DIR" ]; then
        local dir_perms=$(stat -c "%a" "$BACKUP_LOG_DIR" 2>/dev/null)
        if [ "$dir_perms" = "755" ] || [ "$dir_perms" = "750" ]; then
            print_result "PASS" "日志目录权限: $dir_perms" "目录权限设置安全合理 (Directory permission settings secure and reasonable)"
        else
            print_result "WARN" "日志目录权限: $dir_perms" "建议使用755或750权限 (Recommend using 755 or 750 permissions)"
        fi
    fi
}

# ============================================
# 最近备份状态检查函数 (Recent Backup Status Check Function)
# ============================================
# 函数名称 (Function Name): check_recent_backups
# 功能描述 (Function Description):
#   验证最近的备份文件和备份时效性，确保备份策略的有效执行和数据保护的连续性
#   Verify recent backup files and backup timeliness to ensure effective execution of backup strategy and continuity of data protection
# 检查项目 (Check Items):
#   1. 备份目录结构验证 (Backup Directory Structure Verification):
#      - 备份目录的存在性验证 (Backup directory existence verification)
#      - 目录权限和可访问性检查 (Directory permissions and accessibility check)
#      - 备份分类目录的完整性 (Backup classification directory completeness)
#   2. 备份文件统计分析 (Backup File Statistical Analysis):
#      - 备份文件的存在性和数量统计 (Backup file existence and quantity statistics)
#      - 不同格式备份文件的支持 (Support for different format backup files)
#      - 备份文件大小和存储效率分析 (Backup file size and storage efficiency analysis)
#   3. 备份时效性评估 (Backup Timeliness Assessment):
#      - 备份文件的时效性检查 (Backup file timeliness check)
#      - 不同类型备份的时间阈值验证 (Time threshold verification for different backup types)
#      - 备份频率合规性检查 (Backup frequency compliance check)
#   4. 备份策略验证 (Backup Strategy Verification):
#      - 3-2-1备份策略的实施情况 (Implementation of 3-2-1 backup strategy)
#      - 增量和全量备份的平衡性 (Balance of incremental and full backups)
#      - 备份保留策略的执行效果 (Execution effectiveness of backup retention policy)
# 时间阈值说明 (Time Threshold Description):
#   - 日备份 (Daily): 25小时内 (Within 25 hours) - 允许1小时的执行窗口
#   - 周备份 (Weekly): 168小时内 (Within 168 hours) - 7天的执行周期
#   - 月备份 (Monthly): 744小时内 (Within 744 hours) - 31天的执行周期
# 备份策略重要性 (Backup Strategy Importance):
#   - 确保数据丢失时的快速恢复能力 (Ensure rapid recovery capability in case of data loss)
#   - 满足业务连续性和灾难恢复要求 (Meet business continuity and disaster recovery requirements)
#   - 符合数据保护法规和合规要求 (Comply with data protection regulations and compliance requirements)
# 配置建议 (Configuration Recommendations):
#   - 根据业务需求调整备份频率 (Adjust backup frequency according to business needs)
#   - 实施多层次备份策略 (Implement multi-level backup strategy)
#   - 定期测试备份恢复流程 (Regularly test backup recovery procedures)
# 故障排除 (Troubleshooting):
#   - 备份文件缺失：检查备份任务和权限 (Missing backup files: check backup tasks and permissions)
#   - 备份过期：验证cron任务和系统时间 (Backup expired: verify cron tasks and system time)
#   - 目录不存在：检查备份脚本和配置 (Directory not exists: check backup scripts and configuration)
# ============================================
check_recent_backups() {
    echo -e "\n${BLUE}=== 最近备份状态检查 (Recent Backup Status Check) ===${NC}"
    
    # ========================================
    # 备份类型定义和初始化 (Backup Type Definition and Initialization)
    # ========================================
    # 定义需要检查的备份类型数组 (Define array of backup types to check)
    local backup_types=("daily" "weekly" "monthly")
    local total_backups=0
    local valid_backups=0
    
    # ========================================
    # 逐类型备份状态检查 (Per-Type Backup Status Check)
    # ========================================
    # 逐个检查每种类型的备份状态 (Check backup status for each type individually)
    for backup_type in "${backup_types[@]}"; do
        local backup_dir="$BACKUP_BASE_DIR/$backup_type"
        
        echo -e "\n${BLUE}检查${backup_type}备份... (Checking ${backup_type} backups...)${NC}"
        
        # 检查备份目录是否存在 (Check if backup directory exists)
        if [ -d "$backup_dir" ]; then
            # 统计备份文件数量（支持.tar.gz和.gz格式） (Count backup files supporting .tar.gz and .gz formats)
            local backup_count=$(find "$backup_dir" -name "*.tar.gz" -o -name "*.gz" 2>/dev/null | wc -l)
            total_backups=$((total_backups + backup_count))
            
            if [ $backup_count -gt 0 ]; then
                print_result "PASS" "${backup_type}备份存在 ($backup_count 个文件)" "备份文件统计完成，数据保护有效 (Backup file statistics completed, data protection effective)"
                
                # 检查最新备份文件的时效性 (Check timeliness of latest backup file)
                local latest_backup=$(find "$backup_dir" -name "*.tar.gz" -o -name "*.gz" 2>/dev/null | xargs ls -t | head -1)
                if [ -n "$latest_backup" ]; then
                    # 计算备份文件的年龄（以小时为单位） (Calculate backup file age in hours)
                    local backup_age=$(( ($(date +%s) - $(stat -c %Y "$latest_backup")) / 3600 ))
                    local backup_date=$(date -d "@$(stat -c %Y "$latest_backup")" "+%Y-%m-%d %H:%M:%S")
                    
                    # 根据备份类型设置不同的时间阈值 (Set different time thresholds based on backup type)
                    case $backup_type in
                        "daily")
                            local threshold=25    # 日备份：25小时内 (Daily backup: within 25 hours)
                            local description="每日备份策略 (Daily backup strategy)"
                            ;;
                        "weekly")
                            local threshold=168   # 周备份：7天（168小时）内 (Weekly backup: within 7 days/168 hours)
                            local description="每周备份策略 (Weekly backup strategy)"
                            ;;
                        "monthly")
                            local threshold=744   # 月备份：31天（744小时）内 (Monthly backup: within 31 days/744 hours)
                            local description="每月备份策略 (Monthly backup strategy)"
                            ;;
                    esac
                    
                    # 根据时间阈值判断备份是否及时 (Judge backup timeliness based on time threshold)
                    if [ $backup_age -lt $threshold ]; then
                        print_result "PASS" "最新${backup_type}备份及时 (${backup_age}小时前)" "备份时间: $backup_date，$description执行正常 (Backup time: $backup_date, $description executing normally)"
                        valid_backups=$((valid_backups + 1))
                    else
                        print_result "WARN" "最新${backup_type}备份过期 (${backup_age}小时前)" "备份时间: $backup_date，建议检查备份任务调度 (Backup time: $backup_date, recommend checking backup task scheduling)"
                    fi
                    
                    # 检查备份文件大小合理性 (Check backup file size reasonableness)
                    local backup_size=$(stat -c "%s" "$latest_backup" 2>/dev/null)
                    local backup_size_mb=$((backup_size / 1024 / 1024))
                    if [ $backup_size_mb -gt 0 ]; then
                        if [ $backup_size_mb -lt 1 ]; then
                            print_result "WARN" "${backup_type}备份文件较小 (<1MB)" "可能备份不完整，建议检查备份内容 (Backup may be incomplete, recommend checking backup content)"
                        else
                            print_result "PASS" "${backup_type}备份大小: ${backup_size_mb}MB" "备份文件大小合理 (Backup file size reasonable)"
                        fi
                    fi
                else
                    print_result "WARN" "无法获取${backup_type}备份详情" "文件可能损坏或权限不足 (File may be corrupted or insufficient permissions)"
                fi
            else
                print_result "WARN" "未找到${backup_type}备份文件" "可能尚未执行此类型的备份或备份失败 (May not have executed this type of backup or backup failed)"
            fi
        else
            print_result "WARN" "${backup_type}备份目录不存在" "请创建备份目录: $backup_dir (Please create backup directory: $backup_dir)"
        fi
    done
    
    # ========================================
    # 备份状态总结 (Backup Status Summary)
    # ========================================
    echo -e "\n${BLUE}备份状态总结... (Backup Status Summary...)${NC}"
    
    if [ $total_backups -gt 0 ]; then
        print_result "INFO" "备份文件总数: $total_backups" "系统中存在的备份文件统计 (Statistics of backup files in system)"
        print_result "INFO" "有效备份类型: $valid_backups/3" "及时有效的备份策略数量 (Number of timely and effective backup strategies)"
        
        # 评估整体备份健康度 (Assess overall backup health)
        if [ $valid_backups -eq 3 ]; then
            print_result "PASS" "备份策略健康度: 优秀" "所有备份类型都及时有效，数据保护完善 (All backup types are timely and effective, data protection is comprehensive)"
        elif [ $valid_backups -ge 2 ]; then
            print_result "WARN" "备份策略健康度: 良好" "大部分备份有效，建议完善所有备份类型 (Most backups are effective, recommend improving all backup types)"
        elif [ $valid_backups -ge 1 ]; then
            print_result "WARN" "备份策略健康度: 一般" "部分备份有效，需要加强备份策略 (Some backups are effective, need to strengthen backup strategy)"
        else
            print_result "FAIL" "备份策略健康度: 差" "所有备份都过期或缺失，数据保护存在严重风险 (All backups are expired or missing, serious risk to data protection)"
        fi
    else
        print_result "FAIL" "未发现任何备份文件" "系统缺乏数据保护，建议立即配置备份策略 (System lacks data protection, recommend immediately configuring backup strategy)"
    fi
}

# ============================================
# 磁盘空间检查函数 (Disk Space Check Function)
# ============================================
# 函数名称 (Function Name): check_disk_space
# 功能描述 (Function Description):
#   验证备份存储空间的使用情况和可用性，确保备份操作有足够的存储空间
#   Verify backup storage space usage and availability to ensure sufficient storage space for backup operations
# 检查项目 (Check Items):
#   1. 磁盘使用率分析 (Disk Usage Analysis):
#      - 备份分区的磁盘使用率监控 (Backup partition disk usage monitoring)
#      - 可用存储空间大小统计 (Available storage space statistics)
#      - 磁盘空间趋势分析 (Disk space trend analysis)
#   2. 存储容量评估 (Storage Capacity Assessment):
#      - 备份目录的总大小计算 (Total size calculation of backup directory)
#      - 不同备份类型的空间占用 (Space usage of different backup types)
#      - 存储效率和压缩比分析 (Storage efficiency and compression ratio analysis)
#   3. 空间警告机制 (Space Warning Mechanism):
#      - 磁盘空间警告阈值检查 (Disk space warning threshold check)
#      - 多级警告系统（80%, 90%阈值） (Multi-level warning system with 80%, 90% thresholds)
#      - 紧急空间不足处理建议 (Emergency space shortage handling recommendations)
#   4. 存储健康度评估 (Storage Health Assessment):
#      - 存储设备性能监控 (Storage device performance monitoring)
#      - I/O性能和响应时间 (I/O performance and response time)
#      - 存储设备错误和警告检查 (Storage device error and warning check)
# 阈值说明 (Threshold Description):
#   - 绿色区域 (Green Zone): <80% - 存储空间充足 (Sufficient storage space)
#   - 黄色区域 (Yellow Zone): 80-90% - 需要关注 (Needs attention)
#   - 红色区域 (Red Zone): >90% - 紧急处理 (Emergency handling required)
# 存储策略重要性 (Storage Strategy Importance):
#   - 防止备份失败和数据丢失 (Prevent backup failure and data loss)
#   - 确保备份操作的连续性 (Ensure continuity of backup operations)
#   - 优化存储资源利用率 (Optimize storage resource utilization)
# 配置建议 (Configuration Recommendations):
#   - 实施自动清理策略 (Implement automatic cleanup strategy)
#   - 配置存储监控和告警 (Configure storage monitoring and alerting)
#   - 规划存储容量扩展 (Plan storage capacity expansion)
# 故障排除 (Troubleshooting):
#   - 空间不足：清理旧备份或扩展存储 (Insufficient space: clean old backups or expand storage)
#   - 权限问题：检查目录访问权限 (Permission issues: check directory access permissions)
#   - 计算错误：验证文件系统完整性 (Calculation errors: verify filesystem integrity)
# ============================================
check_disk_space() {
    echo -e "\n${BLUE}=== 磁盘空间检查 (Disk Space Check) ===${NC}"
    
    # ========================================
    # 备份目录存在性验证 (Backup Directory Existence Verification)
    # ========================================
    # 检查备份目录是否存在 (Check if backup directory exists)
    if [ -d "$BACKUP_BASE_DIR" ]; then
        echo -e "\n${BLUE}分析存储空间使用情况... (Analyzing storage space usage...)${NC}"
        
        # ========================================
        # 磁盘使用率统计 (Disk Usage Statistics)
        # ========================================
        # 获取备份目录所在分区的磁盘使用率（百分比） (Get disk usage percentage of backup directory partition)
        local usage=$(df "$BACKUP_BASE_DIR" | awk 'NR==2 {print $5}' | sed 's/%//')
        # 获取可用空间（人类可读格式） (Get available space in human-readable format)
        local available=$(df -h "$BACKUP_BASE_DIR" | awk 'NR==2 {print $4}')
        # 获取总空间大小 (Get total space size)
        local total=$(df -h "$BACKUP_BASE_DIR" | awk 'NR==2 {print $2}')
        # 获取已使用空间 (Get used space)
        local used=$(df -h "$BACKUP_BASE_DIR" | awk 'NR==2 {print $3}')
        
        # ========================================
        # 磁盘使用率警告级别判断 (Disk Usage Warning Level Assessment)
        # ========================================
        # 根据磁盘使用率进行警告级别判断 (Judge warning level based on disk usage)
        if [ $usage -lt 80 ]; then
            print_result "PASS" "磁盘使用率: ${usage}% (${used}/${total})" "存储空间充足，备份操作安全 (Sufficient storage space, backup operations safe)"
            print_result "INFO" "可用空间: ${available}" "剩余存储容量良好 (Remaining storage capacity good)"
        elif [ $usage -lt 90 ]; then
            print_result "WARN" "磁盘使用率: ${usage}% (${used}/${total})" "存储空间紧张，建议清理旧备份 (Storage space tight, recommend cleaning old backups)"
            print_result "WARN" "可用空间: ${available}" "需要关注存储容量，建议扩展存储 (Need to monitor storage capacity, recommend expanding storage)"
        else
            print_result "FAIL" "磁盘使用率: ${usage}% (${used}/${total}) - 危险" "存储空间严重不足，备份可能失败 (Seriously insufficient storage space, backup may fail)"
            print_result "FAIL" "可用空间: ${available}" "紧急：需要立即清理空间或扩展存储 (Emergency: need to immediately clean space or expand storage)"
        fi
        
        # ========================================
        # 备份目录大小统计 (Backup Directory Size Statistics)
        # ========================================
        echo -e "\n${BLUE}计算备份数据占用空间... (Calculating backup data space usage...)${NC}"
        
        # 计算备份目录的总大小 (Calculate total size of backup directory)
        local backup_size=$(du -sh "$BACKUP_BASE_DIR" 2>/dev/null | cut -f1)
        if [ -n "$backup_size" ]; then
            print_result "INFO" "备份总大小: $backup_size" "当前备份数据占用空间统计 (Current backup data space usage statistics)"
            
            # 计算各类型备份的大小分布 (Calculate size distribution of different backup types)
            for backup_type in "daily" "weekly" "monthly"; do
                local type_dir="$BACKUP_BASE_DIR/$backup_type"
                if [ -d "$type_dir" ]; then
                    local type_size=$(du -sh "$type_dir" 2>/dev/null | cut -f1)
                    if [ -n "$type_size" ]; then
                        print_result "INFO" "${backup_type}备份大小: $type_size" "${backup_type}备份数据占用空间 (${backup_type} backup data space usage)"
                    fi
                fi
            done
            
            # 计算备份数据占总磁盘的百分比 (Calculate percentage of backup data to total disk)
            local backup_size_bytes=$(du -sb "$BACKUP_BASE_DIR" 2>/dev/null | cut -f1)
            local total_bytes=$(df "$BACKUP_BASE_DIR" | awk 'NR==2 {print $2}')
            if [ -n "$backup_size_bytes" ] && [ -n "$total_bytes" ] && [ $total_bytes -gt 0 ]; then
                local backup_percentage=$(( backup_size_bytes * 100 / (total_bytes * 1024) ))
                print_result "INFO" "备份数据占磁盘比例: ${backup_percentage}%" "备份数据在总存储中的占比 (Backup data proportion in total storage)"
            fi
        else
            print_result "WARN" "无法计算备份目录大小" "可能存在权限问题或目录为空 (May have permission issues or directory is empty)"
        fi
        
        # ========================================
        # 存储性能和健康度检查 (Storage Performance and Health Check)
        # ========================================
        echo -e "\n${BLUE}检查存储设备健康状态... (Checking storage device health...)${NC}"
        
        # 检查文件系统类型 (Check filesystem type)
        local fs_type=$(df -T "$BACKUP_BASE_DIR" | awk 'NR==2 {print $2}')
        print_result "INFO" "文件系统类型: $fs_type" "备份存储使用的文件系统 (Filesystem used for backup storage)"
        
        # 检查inode使用情况 (Check inode usage)
        local inode_usage=$(df -i "$BACKUP_BASE_DIR" | awk 'NR==2 {print $5}' | sed 's/%//')
        if [ $inode_usage -lt 80 ]; then
            print_result "PASS" "inode使用率: ${inode_usage}%" "文件系统inode充足 (Filesystem inodes sufficient)"
        elif [ $inode_usage -lt 90 ]; then
            print_result "WARN" "inode使用率: ${inode_usage}%" "inode使用率较高，注意文件数量 (High inode usage, monitor file count)"
        else
            print_result "FAIL" "inode使用率: ${inode_usage}%" "inode不足，可能影响文件创建 (Insufficient inodes, may affect file creation)"
        fi
        
    else
        print_result "FAIL" "无法检查磁盘空间 - 备份目录未找到" "请先创建备份目录: $BACKUP_BASE_DIR (Please create backup directory first: $BACKUP_BASE_DIR)"
    fi
}

# ============================================
# 备份功能测试函数 (Backup Functionality Test Function)
# ============================================
# 函数名称 (Function Name): test_backup_functionality
# 功能描述 (Function Description):
#   验证备份脚本的功能性和可用性，确保备份系统的各个组件能够正常工作
#   Verify backup script functionality and availability to ensure all components of backup system work properly
# 检查项目 (Check Items):
#   1. 备份脚本功能验证 (Backup Script Function Verification):
#      - 备份脚本的可执行性检查 (Backup script executability check)
#      - 脚本测试模式（干运行）验证 (Script test mode (dry run) verification)
#      - 脚本参数和选项支持 (Script parameter and option support)
#   2. 脚本接口测试 (Script Interface Testing):
#      - 帮助信息的可用性检查 (Help information availability check)
#      - 命令行参数解析测试 (Command line parameter parsing test)
#      - 错误处理和退出码验证 (Error handling and exit code verification)
#   3. 恢复脚本功能验证 (Restore Script Function Verification):
#      - 恢复脚本的可执行性和完整性 (Restore script executability and integrity)
#      - 恢复流程的可用性检查 (Restore process availability check)
#      - 恢复选项和参数支持 (Restore options and parameter support)
#   4. 验证脚本功能测试 (Verification Script Function Testing):
#      - 验证脚本的功能性检查 (Verification script functionality check)
#      - 备份完整性验证能力 (Backup integrity verification capability)
#      - 自动化验证流程支持 (Automated verification process support)
#   5. 脚本集成测试 (Script Integration Testing):
#      - 脚本间的协调和通信 (Coordination and communication between scripts)
#      - 配置文件的共享和一致性 (Configuration file sharing and consistency)
#      - 日志记录和错误报告 (Logging and error reporting)
# 测试策略 (Testing Strategy):
#   - 非破坏性测试：使用干运行模式 (Non-destructive testing: use dry run mode)
#   - 接口测试：验证命令行接口 (Interface testing: verify command line interface)
#   - 功能测试：检查核心功能可用性 (Functional testing: check core functionality availability)
# 脚本质量评估 (Script Quality Assessment):
#   - 代码规范和最佳实践 (Code standards and best practices)
#   - 错误处理和异常管理 (Error handling and exception management)
#   - 用户体验和易用性 (User experience and usability)
# 配置建议 (Configuration Recommendations):
#   - 实施脚本版本控制 (Implement script version control)
#   - 添加详细的帮助文档 (Add detailed help documentation)
#   - 支持多种运行模式 (Support multiple execution modes)
# 故障排除 (Troubleshooting):
#   - 脚本不可执行：检查权限和路径 (Script not executable: check permissions and path)
#   - 功能缺失：更新脚本或添加功能 (Missing functionality: update script or add features)
#   - 接口问题：检查参数解析逻辑 (Interface issues: check parameter parsing logic)
# ============================================
test_backup_functionality() {
    echo -e "\n${BLUE}=== 备份功能测试 (Backup Functionality Test) ===${NC}"
    
    # ========================================
    # 主备份脚本功能测试 (Main Backup Script Function Testing)
    # ========================================
    echo -e "\n${BLUE}测试主备份脚本... (Testing main backup script...)${NC}"
    
    # 测试主备份脚本的功能 (Test main backup script functionality)
    local backup_script="$BACKUP_SCRIPTS_DIR/backup.sh"
    if [ -x "$backup_script" ]; then
        print_result "PASS" "备份脚本可执行" "脚本权限和路径配置正确 (Script permissions and path configured correctly)"
        
        # 测试备份脚本的干运行模式（不实际执行备份） (Test backup script dry run mode without actual backup execution)
        echo -e "\n${BLUE}测试备份脚本干运行模式... (Testing backup script dry run mode...)${NC}"
        if "$backup_script" --test >/dev/null 2>&1; then
            print_result "PASS" "备份脚本测试模式正常" "脚本支持安全的测试运行，可进行无风险验证 (Script supports safe test run for risk-free verification)"
        elif "$backup_script" --dry-run >/dev/null 2>&1; then
            print_result "PASS" "备份脚本干运行模式正常" "脚本支持干运行模式 (Script supports dry run mode)"
        else
            print_result "WARN" "备份脚本测试模式不支持" "建议添加--test或--dry-run参数支持 (Recommend adding --test or --dry-run parameter support)"
        fi
        
        # 测试备份脚本的帮助信息 (Test backup script help information)
        echo -e "\n${BLUE}测试备份脚本帮助信息... (Testing backup script help information...)${NC}"
        if "$backup_script" --help >/dev/null 2>&1; then
            print_result "PASS" "备份脚本帮助信息可用" "脚本提供了完整的使用说明和参数文档 (Script provides complete usage instructions and parameter documentation)"
        elif "$backup_script" -h >/dev/null 2>&1; then
            print_result "PASS" "备份脚本帮助信息可用(-h)" "脚本支持简短帮助选项 (Script supports short help option)"
        else
            print_result "WARN" "备份脚本帮助信息不可用" "建议添加--help参数支持以提高用户体验 (Recommend adding --help parameter support to improve user experience)"
        fi
        
        # 测试备份脚本的版本信息 (Test backup script version information)
        if "$backup_script" --version >/dev/null 2>&1; then
            print_result "PASS" "备份脚本版本信息可用" "脚本支持版本查询，便于维护管理 (Script supports version query for maintenance management)"
        else
            print_result "INFO" "备份脚本版本信息不可用" "建议添加--version参数支持 (Recommend adding --version parameter support)"
        fi
        
    else
        print_result "FAIL" "备份脚本不可执行或未找到" "请检查脚本路径和权限: $backup_script (Please check script path and permissions: $backup_script)"
    fi
    
    # ========================================
    # 恢复脚本功能测试 (Restore Script Function Testing)
    # ========================================
    echo -e "\n${BLUE}测试恢复脚本... (Testing restore script...)${NC}"
    
    # 测试恢复脚本的功能 (Test restore script functionality)
    local restore_script="$BACKUP_SCRIPTS_DIR/restore.sh"
    if [ -x "$restore_script" ]; then
        print_result "PASS" "恢复脚本可执行" "恢复脚本权限和路径配置正确 (Restore script permissions and path configured correctly)"
        
        # 检查恢复脚本的帮助信息 (Check restore script help information)
        if "$restore_script" --help >/dev/null 2>&1; then
            print_result "PASS" "恢复脚本帮助信息可用" "恢复脚本提供了详细的使用说明 (Restore script provides detailed usage instructions)"
        elif "$restore_script" -h >/dev/null 2>&1; then
            print_result "PASS" "恢复脚本帮助信息可用(-h)" "恢复脚本支持简短帮助选项 (Restore script supports short help option)"
        else
            print_result "WARN" "恢复脚本帮助信息不可用" "建议添加--help参数支持 (Recommend adding --help parameter support)"
        fi
        
        # 测试恢复脚本的列表功能 (Test restore script list functionality)
        if "$restore_script" --list >/dev/null 2>&1; then
            print_result "PASS" "恢复脚本列表功能可用" "可以列出可用的备份文件 (Can list available backup files)"
        else
            print_result "INFO" "恢复脚本列表功能不可用" "建议添加--list参数支持 (Recommend adding --list parameter support)"
        fi
        
    else
        print_result "FAIL" "恢复脚本不可执行或未找到" "请检查恢复脚本的存在性和权限: $restore_script (Please check restore script existence and permissions: $restore_script)"
    fi
    
    # ========================================
    # 验证脚本功能测试 (Verification Script Function Testing)
    # ========================================
    echo -e "\n${BLUE}测试验证脚本... (Testing verification script...)${NC}"
    
    # 测试验证脚本的功能 (Test verification script functionality)
    local verify_script="$BACKUP_SCRIPTS_DIR/verify.sh"
    if [ -x "$verify_script" ]; then
        print_result "PASS" "验证脚本可执行" "验证脚本权限和路径配置正确 (Verification script permissions and path configured correctly)"
        
        # 检查验证脚本的帮助信息 (Check verification script help information)
        if "$verify_script" --help >/dev/null 2>&1; then
            print_result "PASS" "验证脚本帮助信息可用" "验证脚本提供了完整的使用说明 (Verification script provides complete usage instructions)"
        elif "$verify_script" -h >/dev/null 2>&1; then
            print_result "PASS" "验证脚本帮助信息可用(-h)" "验证脚本支持简短帮助选项 (Verification script supports short help option)"
        else
            print_result "WARN" "验证脚本帮助信息不可用" "建议添加--help参数支持 (Recommend adding --help parameter support)"
        fi
        
        # 测试验证脚本的快速检查模式 (Test verification script quick check mode)
        if "$verify_script" --quick >/dev/null 2>&1; then
            print_result "PASS" "验证脚本快速检查模式可用" "支持快速验证模式 (Supports quick verification mode)"
        else
            print_result "INFO" "验证脚本快速检查模式不可用" "建议添加--quick参数支持 (Recommend adding --quick parameter support)"
        fi
        
    else
        print_result "FAIL" "验证脚本不可执行或未找到" "请检查验证脚本的存在性和权限: $verify_script (Please check verification script existence and permissions: $verify_script)"
    fi
    
    # ========================================
    # 脚本集成和协调测试 (Script Integration and Coordination Testing)
    # ========================================
    echo -e "\n${BLUE}测试脚本集成和协调... (Testing script integration and coordination...)${NC}"
    
    # 检查脚本间的配置一致性 (Check configuration consistency between scripts)
    local config_files_count=0
    for script in "$backup_script" "$restore_script" "$verify_script"; do
        if [ -x "$script" ] && grep -q "BACKUP_BASE_DIR" "$script" 2>/dev/null; then
            config_files_count=$((config_files_count + 1))
        fi
    done
    
    if [ $config_files_count -gt 0 ]; then
        print_result "PASS" "脚本配置一致性检查" "$config_files_count 个脚本使用统一配置 ($config_files_count scripts use unified configuration)"
    else
        print_result "WARN" "脚本配置一致性检查" "建议统一脚本配置管理 (Recommend unified script configuration management)"
    fi
    
    # 检查脚本的日志记录能力 (Check script logging capability)
    local logging_scripts=0
    for script in "$backup_script" "$restore_script" "$verify_script"; do
        if [ -x "$script" ] && (grep -q "log" "$script" 2>/dev/null || grep -q "LOG" "$script" 2>/dev/null); then
            logging_scripts=$((logging_scripts + 1))
        fi
    done
    
    if [ $logging_scripts -gt 0 ]; then
        print_result "PASS" "脚本日志记录能力" "$logging_scripts 个脚本支持日志记录 ($logging_scripts scripts support logging)"
    else
        print_result "WARN" "脚本日志记录能力" "建议添加日志记录功能 (Recommend adding logging functionality)"
    fi
}

# ============================================
# 显示验证摘要函数 / Display Verification Summary Function
# 功能：显示验证结果的详细摘要和评分
# Function: Display detailed summary and scoring of verification results
# 
# 主要功能 / Main Functions:
#   1. 检查统计信息显示 / Display check statistics
#      - 总检查项数量 / Total number of checks
#      - 通过项统计 / Passed checks count
#      - 失败项统计 / Failed checks count
#      - 警告项统计 / Warning checks count
#   2. 系统评分计算 / System scoring calculation
#      - 基于通过率的百分比评分 / Percentage score based on pass rate
#      - 系统健康状态评估 / System health status assessment
#   3. 状态评估和建议 / Status assessment and recommendations
#      - 优秀：无失败无警告 / Excellent: no failures, no warnings
#      - 良好：无失败有警告 / Good: no failures, some warnings
#      - 需要处理：有失败项 / Needs attention: has failures
#   4. 快速命令参考 / Quick command reference
#      - 常用备份管理命令 / Common backup management commands
#      - 重要文件路径信息 / Important file path information
# 
# 输出格式 / Output Format:
#   - 彩色格式化输出 / Colored formatted output
#   - 清晰的统计信息 / Clear statistical information
#   - 实用的命令参考 / Practical command reference
#   - 重要路径快速访问 / Quick access to important paths
# 
# 使用场景 / Use Cases:
#   - 验证完成后的结果展示 / Result display after verification completion
#   - 系统状态快速评估 / Quick system status assessment
#   - 运维人员操作指导 / Operations guidance for administrators
#   - 自动化监控报告 / Automated monitoring reports
# ============================================
display_summary() {
    echo -e "\n${BLUE}=== 备份验证摘要 ===${NC}"
    
    # 显示检查统计信息 / Display check statistics
    # 提供清晰的数字统计，便于快速了解系统状态
    # Provide clear numerical statistics for quick system status understanding
    echo -e "总检查项 / Total Checks: $TOTAL_CHECKS"
    echo -e "${GREEN}✓ 通过 / Passed: $PASSED_CHECKS${NC}"  # 绿色显示通过项
    echo -e "${RED}✗ 失败 / Failed: $FAILED_CHECKS${NC}"   # 红色显示失败项
    echo -e "${YELLOW}⚠ 警告 / Warnings: $WARNING_CHECKS${NC}" # 黄色显示警告项
    
    # 计算系统评分（基于通过的检查项百分比）/ Calculate system score (based on passed checks percentage)
    # 评分算法：(通过项数 / 总检查项数) × 100
    # Scoring algorithm: (passed checks / total checks) × 100
    local score=$((PASSED_CHECKS * 100 / TOTAL_CHECKS))
    echo -e "\n📊 备份系统评分 / Backup System Score: ${BLUE}$score%${NC}"
    
    # 评分等级说明 / Score level explanation
    if [ $score -ge 90 ]; then
        echo -e "   评级 / Rating: ${GREEN}优秀 / Excellent (90-100%)${NC}"
    elif [ $score -ge 80 ]; then
        echo -e "   评级 / Rating: ${YELLOW}良好 / Good (80-89%)${NC}"
    elif [ $score -ge 70 ]; then
        echo -e "   评级 / Rating: ${YELLOW}一般 / Fair (70-79%)${NC}"
    else
        echo -e "   评级 / Rating: ${RED}需要改进 / Needs Improvement (<70%)${NC}"
    fi
    
    # 根据检查结果提供系统状态评估 / Provide system status assessment based on check results
    echo -e "\n🏥 系统健康状态 / System Health Status:"
    if [ $FAILED_CHECKS -eq 0 ] && [ $WARNING_CHECKS -eq 0 ]; then
        echo -e "${GREEN}✓ 优秀！所有备份检查都通过了。${NC}"
        echo -e "${GREEN}  Excellent! All backup checks passed.${NC}"
        echo -e "  💡 建议 / Recommendation: 继续保持当前配置和维护策略"
        echo -e "     Continue current configuration and maintenance strategy"
    elif [ $FAILED_CHECKS -eq 0 ]; then
        echo -e "${YELLOW}⚠ 良好！没有失败项，但有一些警告需要处理。${NC}"
        echo -e "${YELLOW}  Good! No failures, but some warnings need attention.${NC}"
        echo -e "  💡 建议 / Recommendation: 处理警告项以优化系统性能"
        echo -e "     Address warning items to optimize system performance"
    else
        echo -e "${RED}✗ 检测到备份系统问题。请处理失败的检查项。${NC}"
        echo -e "${RED}  Issues detected in backup system. Please address failed checks.${NC}"
        echo -e "  🚨 紧急 / Urgent: 立即处理失败项以确保数据安全"
        echo -e "     Address failures immediately to ensure data safety"
    fi
    
    # 提供常用的备份管理命令参考 / Provide common backup management command reference
    echo -e "\n${BLUE}📋 快速命令参考 / Quick Command Reference:${NC}"
    echo -e "${CYAN}备份操作 / Backup Operations:${NC}"
    echo -e "  手动备份 / Manual Backup:     ${GREEN}$BACKUP_SCRIPTS_DIR/backup.sh [daily|weekly|monthly]${NC}"
    echo -e "    └─ 执行指定类型的备份 / Execute specified type of backup"
    echo -e "  验证备份 / Verify Backup:     ${GREEN}$BACKUP_SCRIPTS_DIR/verify.sh${NC}"
    echo -e "    └─ 验证备份文件完整性 / Verify backup file integrity"
    echo -e "  清理备份 / Cleanup Backup:   ${GREEN}$BACKUP_SCRIPTS_DIR/cleanup.sh${NC}"
    echo -e "    └─ 清理过期的备份文件 / Clean up expired backup files"
    
    echo -e "${CYAN}恢复操作 / Restore Operations:${NC}"
    echo -e "  恢复帮助 / Restore Help:      ${GREEN}$BACKUP_SCRIPTS_DIR/restore.sh --help${NC}"
    echo -e "    └─ 查看恢复选项和用法 / View restore options and usage"
    echo -e "  列表备份 / List Backups:      ${GREEN}$BACKUP_SCRIPTS_DIR/restore.sh --list${NC}"
    echo -e "    └─ 列出可用的备份文件 / List available backup files"
    
    echo -e "${CYAN}监控操作 / Monitoring Operations:${NC}"
    echo -e "  系统状态 / System Status:     ${GREEN}/usr/local/bin/backup-status${NC}"
    echo -e "    └─ 查看备份系统状态 / View backup system status"
    echo -e "  重新验证 / Re-verify:         ${GREEN}$0${NC}"
    echo -e "    └─ 重新运行此验证脚本 / Re-run this verification script"
    
    # 提供配置文件和日志文件的快速访问路径 / Provide quick access paths for config and log files
    echo -e "\n${BLUE}📁 重要文件路径 / Important File Paths:${NC}"
    echo -e "${CYAN}配置文件 / Configuration Files:${NC}"
    echo -e "  主配置 / Main Config:         ${GREEN}$BACKUP_CONFIG_FILE${NC}"
    echo -e "    └─ 备份系统主配置文件 / Main backup system configuration file"
    echo -e "  Cron配置 / Cron Config:       ${GREEN}/etc/cron.d/backup-*${NC}"
    echo -e "    └─ 定时任务配置文件 / Scheduled task configuration files"
    echo -e "  日志轮转 / Log Rotation:      ${GREEN}/etc/logrotate.d/backup${NC}"
    echo -e "    └─ 日志轮转配置文件 / Log rotation configuration file"
    
    echo -e "${CYAN}数据目录 / Data Directories:${NC}"
    echo -e "  备份存储 / Backup Storage:    ${GREEN}$BACKUP_BASE_DIR${NC}"
    echo -e "    └─ 备份文件存储根目录 / Backup files storage root directory"
    echo -e "  日志目录 / Log Directory:     ${GREEN}$BACKUP_LOG_DIR${NC}"
    echo -e "    └─ 备份操作日志存储位置 / Backup operation logs storage location"
    echo -e "  脚本目录 / Scripts Directory: ${GREEN}$BACKUP_SCRIPTS_DIR${NC}"
    echo -e "    └─ 备份脚本存储位置 / Backup scripts storage location"
    
    echo -e "${CYAN}系统服务 / System Services:${NC}"
    echo -e "  服务状态 / Service Status:    ${GREEN}systemctl status backup-monitor${NC}"
    echo -e "  定时器状态 / Timer Status:    ${GREEN}systemctl status backup-monitor.timer${NC}"
    echo -e "  服务日志 / Service Logs:      ${GREEN}journalctl -u backup-monitor${NC}"
}

# ============================================
# 主执行流程 / Main Execution Flow
# 功能：脚本的主要执行流程和入口点
# Function: Main execution flow and entry point of the script
# 
# 执行流程 / Execution Flow:
#   1. 脚本初始化 / Script initialization
#      - 显示脚本标题和版本信息 / Display script title and version info
#      - 显示当前执行时间 / Display current execution time
#      - 初始化全局变量和计数器 / Initialize global variables and counters
#   2. 系统验证检查 / System verification checks
#      - 按逻辑顺序执行所有检查项 / Execute all checks in logical order
#      - 每个检查项独立执行和报告 / Each check executes and reports independently
#      - 累计统计检查结果 / Accumulate check results statistics
#   3. 结果汇总和报告 / Results summary and reporting
#      - 显示详细的验证结果摘要 / Display detailed verification results summary
#      - 提供系统评分和健康状态 / Provide system scoring and health status
#      - 给出操作建议和命令参考 / Provide operational recommendations and command reference
#   4. 退出码处理 / Exit code handling
#      - 根据检查结果返回适当退出码 / Return appropriate exit code based on check results
#      - 便于自动化脚本和监控集成 / Facilitate automation scripts and monitoring integration
# 
# 设计原则 / Design Principles:
#   - 模块化检查：每个检查项独立且可重用 / Modular checks: each check is independent and reusable
#   - 渐进式验证：从基础到高级逐步检查 / Progressive verification: from basic to advanced checks
#   - 用户友好：清晰的输出和有用的建议 / User-friendly: clear output and useful recommendations
#   - 自动化兼容：标准化的退出码和输出格式 / Automation compatible: standardized exit codes and output format
# ============================================

# 显示脚本标题和执行时间
echo -e "${BLUE}╔══════════════════════════════════════════════════════════════╗${NC}"
echo -e "${BLUE}║                  备份验证脚本                 ║${NC}"
echo -e "${BLUE}║                     $(date '+%Y-%m-%d %H:%M:%S')                     ║${NC}"
echo -e "${BLUE}╚══════════════════════════════════════════════════════════════╝${NC}"

# 按顺序执行所有备份系统验证检查
echo -e "\n${BLUE}开始执行备份系统验证检查...${NC}"

# 1. 检查备份目录结构和权限
check_backup_directories

# 2. 检查备份脚本的存在性和可执行性
check_backup_scripts

# 3. 检查备份配置文件和设置
check_backup_configuration

# 4. 检查备份用户账户和权限
check_backup_user

# 5. 检查定时任务配置
check_cron_jobs

# 6. 检查系统服务状态
check_systemd_services

# 7. 检查日志轮转配置
check_log_rotation

# 8. 检查最近的备份状态
check_recent_backups

# 9. 检查磁盘空间使用情况
check_disk_space

# 10. 测试备份功能的可用性
test_backup_functionality

# 显示验证结果摘要和建议
display_summary

# ============================================
# 退出码处理
# 功能：根据验证结果返回适当的退出码
# 退出码说明：
#   0 - 成功：所有检查都通过，无警告
#   1 - 失败：存在失败的检查项，需要立即处理
#   2 - 警告：无失败项，但存在警告，建议处理
# 用途：便于自动化脚本和监控系统判断备份系统状态
# ============================================
if [ $FAILED_CHECKS -gt 0 ]; then
    # 存在失败的检查项，返回错误退出码
    echo -e "\n${RED}脚本执行完成，发现 $FAILED_CHECKS 个失败项，请及时处理。${NC}"
    exit 1
elif [ $WARNING_CHECKS -gt 0 ]; then
    # 无失败项但有警告，返回警告退出码
    echo -e "\n${YELLOW}脚本执行完成，发现 $WARNING_CHECKS 个警告项，建议处理。${NC}"
    exit 2
else
    # 所有检查都通过，返回成功退出码
    echo -e "\n${GREEN}脚本执行完成，备份系统状态良好！${NC}"
    exit 0
fi